PDA

View Full Version : php "for" application help



ckevin
June 2nd, 2002, 12:16
I'm new to PHP and writing a PHP program which I want to utilize "for" as follows:


echo "<p>$pti13 ";
for ($i=1; $i < 6; $i++) {
echo "<input type=\"radio\" name=\"pti_index13\" ";
if ($formValues["pti_index13"] == '$i') {
echo "checked ";
}
echo "value=\"$i\">&nbsp;&nbsp; \n";
}
echo "</p>\n";

However, it can't work properly, while if I don't use "for" (as follows) it can work without problem, so anyone can figure what's wrong with my "for" command?


printf("<p>$pti13 ");
printf("<input type=\"radio\" name=\"pti_index13\" value=\"1\"");
if ($formValues["pti_index13"] == '1') {
printf(" checked");
}
printf(">&nbsp;&nbsp; \n");

printf("<input type=\"radio\" name=\"pti_index13\" value=\"2\"");
if ($formValues["pti_index13"] == '2') {
printf(" checked");
}
printf(">&nbsp;&nbsp; \n");

printf("<input type=\"radio\" name=\"pti_index13\" value=\"3\"");
if ($formValues["pti_index13"] == '3') {
printf(" checked");
}
printf(">&nbsp;&nbsp; \n");

printf("<input type=\"radio\" name=\"pti_index13\" value=\"4\"");
if ($formValues["pti_index13"] == '4') {
printf(" checked");
}
printf(">&nbsp;&nbsp; \n");

printf("<input type=\"radio\" name=\"pti_index13\" value=\"5\"");
if ($formValues["pti_index13"] == '5') {
printf(" checked");
}
printf(">\n");

printf("</p>\n");

Thanks in advance!

Cyber
June 2nd, 2002, 12:25
echo "<input type=\"radio\" name=\"pti_index13\" >>>>>"<<<<;

where the >>>>>'s are

ckevin
June 2nd, 2002, 12:27
Cyber, I have those >>>>>"<<<< characters... :rolleyes:

Christopher
June 2nd, 2002, 12:41
Well, if $i is a number, then when your testing it, take away the ' around it...

spec
June 2nd, 2002, 15:16
can u post the form values? It seems to work but i get variable errors for the values that are undefined

ckevin
June 2nd, 2002, 21:27
Christopher, your tip is helpful! When I removed it, it worked!

Besides, thank you spec and cyber! :)

ckevin
June 2nd, 2002, 21:33
btw, I have another simple php problem, I have no output for the $month["$ii"] if...


echo "<select name=\"mm\">\n";
for ($i=1; $i < 13; $i++) {
echo "\t\t\t<option value=\"$i\"";
selectm($i);
if ($i < 10) {
$ii = "0".$i;
} else {
$ii = "$i";
}
echo ">".$month["$ii"]."</option>\n";
}
echo "</select>\n";
$month["$ii"] is for:

$month["01"] = "January";
$month["02"] = "February";
$month["03"] = "March";
$month["04"] = "April";
$month["05"] = "May";
$month["06"] = "June";
$month["07"] = "July";
$month["08"] = "August";
$month["09"] = "September";
$month["10"] = "October";
$month["11"] = "November";
$month["12"] = "December";

However, I have output if simply replace it with $ii :(

Thanks in advance!

spec
June 2nd, 2002, 22:56
You are still using "" around integers
anything that is a number you dont quote.
Try removing quotes from the array index's also.
Why not make the indexes

$month[1] = "January";
$month[2] = "February";
$month[3] = "March";
$month[4] = "April";
$month[5] = "May";
$month[6] = "June";
$month[7] = "July";
$month[8] = "August";
$month[9] = "September";
$month[10] = "October";
$month[11] = "November";
$month[12] = "December";

and use this code for your select box



echo "<select name=\"mm\">\n";
for ($i=1; $i < 13; $i++) {
echo "\t\t\t<option value=" . $i . ">" . $month[$i] . "</option>\n";
}
echo "</select>\n";

Canuckkev
June 2nd, 2002, 22:58
What's the point of all this?


selectm($i);

if ($i < 10) {

$ii = "0".$i;

} else {

$ii = "$i";

}



Why not just use $month[$i] ?

ckevin
June 3rd, 2002, 10:47
um.. this time, I believe the problem is I have to include those defined month text inside the "for" tags, after I done that, it can be solved... so strange, if I move out of the "for" tag, it gives no value... however, thanks for all of your help! :)