Welcome, Guest. Please login or register.
Did you miss your activation email?
July 09, 2008, 09:36:22 am
42751 Posts in 8091 Topics by 17932 Members
Latest Member: codder
Turk-Php.Com Forum  |  Yardım Forumları  |  PHP Yardım Forumu  |  for döngüsü kadar değişken tanımlamak « previous next »
Pages: [1] Print
Author Topic: for döngüsü kadar değişken tanımlamak  (Read 96 times)
gunescan
Yeni Kullanıcılar
*
Offline Offline

Posts: 5


View Profile WWW
for döngüsü kadar değişken tanımlamak
« on: May 11, 2008, 06:46:52 am »

Arkadaslar;

Code:
<?php
for($i=$i <= 10 ; $++) {
 
// burada dönme sayısı kadar değişken tanımlayabilir miyiz?
 // dizi yapabiliriz galiba şimdi aklıma geldi
 // dizi ise nasıl yaparım?
}
?>


mesele şu; bir sayfam var not ortalaması hesaplamak için.
ilk önce kaç not gireceksiniz diyerek text field'den not sayısını alıyorum.
daha sonra not sayısı kadar text field'i ekrana basıyorum buraya kadar tamam.
ama bu notların yazıldıgı text fieldlerle işlem yapmam için değişken lazım. orada tıkandım.

işte sayfam:
Code:
<form id="form1" name="form1" method="post" action="gpa.php">
  <label>How many lectures?:
  <input name="cntLect" type="text" id="howManyLec"  size="10" maxlength="2"/>
  </label>
  <input type="submit" name="send" id="send" value="Submit" />
</form>
  <?php
$cntLect 
$_POST['cntLect'];

if((
$cntLect != NULL) || ($cntLect != 0)) {
echo 
"<form id=\"form2\" name=\"form2\" method=\"post\" action=\"gpa.php\">";
for($i=1;$i<=$cntLect;$i++) {
 
echo "<label>Lecture " $i ":";
  
echo "<input type=\"text\" name=\"lecture" $i "\" id=\"textfield\" />";
  
echo "</label>";
echo "<br>";
}
echo "<input type=\"submit\" name=\"send\" id=\"send\" value=\"Submit\" />";
echo 
"</form>";
}
?>

« Last Edit: May 11, 2008, 06:52:10 am by gunescan » Logged

İlle de PHP ...!  :evil:
mahirix
PHP Stajyeri
**
Offline Offline

Posts: 192



View Profile
Ynt: for döngüsü kadar değişken tanımlamak
« Reply #1 on: May 11, 2008, 09:21:38 am »

Code:
<form id="form1" name="form1" method="post" action="<?=$_SERVER["PHP_SELF"]?>">
  <label>How many lectures?:
  <input name="cntLect" type="text" id="howManyLec"  value="<?=$cntLect?>" size="10" maxlength="2"/>
  </label>
  <input type="submit" name="send" id="send" value="Submit" />
</form>
  <?php
$cntLect 
$_POST['cntLect'];

if((
$cntLect != NULL) || ($cntLect != 0)) {
echo 
"<form id=\"form2\" name=\"form2\" method=\"post\" action=\"degerlendir.php\">";
$lecture = array();
for(
$i=1;$i<=$cntLect;$i++) {
  echo 
"<label>Lecture " $i ":";
   echo 
"<input type=\"text\" name=\"lecture[]\" id=\"textfield\" />";
   echo 
"</label>";
echo 
"<br>";
}
echo 
"<input type=\"submit\" name=\"send\" id=\"send\" value=\"Submit\" />";
echo 
"</form>";
}
?>



Code:
<?php
$lecture 
$_POST["lecture"];

foreach(
$lecture as $deger){

echo $deger ."<br />";
}

?>

Logged

Pages: [1] Print 
« previous next »
Jump to: