|
|
|
Author
|
Topic: for döngüsü kadar değişken tanımlamak (Read 96 times)
|
|
gunescan
|
Arkadaslar; <?php for($i=1 ; $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: <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
|
<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>"; } ?>
<?php $lecture = $_POST["lecture"];
foreach($lecture as $deger){
echo $deger ."<br />"; }
?>
|
|
|
|
|
Logged
|
|
|
|
|
 |
|