Re: Please Help with LOOP!!
| From: | Asmodean | Date: | Fri, 19 Jul 2002 00:47:31 +0000 |
| Subject: | Re: Please Help with LOOP!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108359@lists.php.net to get a copy of this message | ||
Hello Wee,
Friday, July 19, 2002, 2:36:40 AM, you wrote:
WK> Hi all...
WK> I'm a complete beginner in programming. Just started a few months ago.
WK> So, I'm sorry if this is a stupid question to ask. But I'm at a dead end here and
WK> do not know where else to go.
WK> I'm trying to automate a checkbox name to have the name "choice1" to have
WK> incremental effect on the number such as the following:
WK> <input type="checkbox" name="choice1" value="x">
WK> <input type="checkbox" name="choice2" value="x">
WK> <input type="checkbox" name="choice3" value="x">
WK> ...
WK> And I used the following script (please don't laugh) :)
WK> Maximise this email to full screen so that you can see the script better.
WK> for($count=1; $count<=$rows; $count++) {
WK> while($query_data = mysql_fetch_array($result)) {
WK> $price = $query_data["price_lq"];
WK> $RowColor = useColor();
WK> echo "<TR BGCOLOR=\"$RowColor\">\n";
WK> echo "<TD width=\"10%\" valign=\"top\"><font
WK> size=\"2\" face=\"Arial, Helvetica,
WK> sans-serif\">",$query_data["prod_brand"],"<BR></FONT</TD>";
WK> echo "<TD width=\"60%\" valign=\"top\"><font
WK> size=\"2\" face=\"Arial, Helvetica,
WK> sans-serif\">",$query_data["prod_desc"],"<BR></FONT></TD>";
WK> echo "<TD width=\"15%\" valign=\"top\<font size=\"2\"
WK> face=\"Arial, Helvetica,
WK> sans-serif\">","$",$price,"<BR></FONT></TD>";
WK> echo "<TD width=\"15%\" valign=\"top\"><input
WK> type=\"checkbox\" name=\"choice",$count,"\" value=\"",
WK> $query_data["prod_id"],"\"></TD>\n</TR>";
WK> }
WK> }
WK> The result was irritating... it came up with the same name, which is "choice1" all
WK> the way like:
WK> <input type="checkbox" name="choice1" value="x">
WK> <input type="checkbox" name="choice1" value="x">
WK> <input type="checkbox" name="choice1" value="x">
WK> ...
WK> Am I doing it the wrong way? If so, how should I do it?
WK> Please pleas help... thanks
WK> Yours,
WK> Wee Keat
WK> ------------------------------------------------------------
WK> "Good timber does not grow with ease; the stronger the wind, the stronger the
WK> trees."
echo "<TD width=\"15%\" valign=\"top\"><input
type=\"checkbox\" name=\"choice",$count,"\" value=\"",
$query_data["prod_id"],"\"></TD>\n</TR>";
Your problem is with this line. Look closely at the following part:
name=\"choice",$count,"\"
You should do this:
name=\"choice" . $count . "\"
... and it will generate names like 'choice1', 'choice2', and so on.
--
Best regards,
Asmodean mailto:asmodean@lka.nu