Re: Forms and While Loop
| From: | Philip Olson | Date: | Wed, 01 Nov 2000 23:18:42 +0000 |
| Subject: | Re: Forms and While Loop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23267@lists.php.net to get a copy of this message | ||
Hey Wayne-
First, putting variables like this in the action line is not standard for
what you are wanting to do, see below. Second, just because you have
variables created does not mean they will pass to the next page - they
have to be specifically passed which in this case $Cat is not passed as a
variable. Thirdly, mix in some single quotes - data does not parse within
single quotes and you can indeed put normal looking double quoted data
within them without worry. Will post a string tutorial later. Regarding
the code, try this :
<?php
echo '<form method="get"
action="'.$Relative.'/items.php">';
echo '<select name="CatList" size="1">';
while ($row = mysql_fetch_row($result))
{
$Cat = $row[0];
$CatID = $row[1];
echo '<option
value="'.$Cat.'">'.$Cat.'</option>';
}
echo '</select>';
echo '<input type="submit" name="submit" value="Go to
Category">';
echo '<input type="Hidden" name="CatID"
value="'.$CatID.'">';
echo '</form>';
?>
Putting a variable in hidden field is a way you can send variables/data.
This above will produce the following for items.php to play with :
$CatList from <select> , value is from <option>$Cat
$CatID from hidden field
You may want to rename your variables to be a bit more
description/specific, I am not sure your intention so made guesses, but
you should figure it out now. But in the above there is no $Cat variable
per se, it is used as a value of the $CatList select - if this is not your
intention you can change accordingly.
Regarding that tutorial, check out :
http://www.zend.com/zend/tut/using-strings.php
It's about strings. You will want to read this and print it out and read
it again, then again after that. It's a good one.
Also, I am unsure where UID came from so did not include that but the
above should give you an idea to complete the job. Good luck! :-)
Philip
-- be outside the box.
On Thu, 2 Nov 2000, Wayne Michel wrote:
> I am trying to produce a drop-down list. Relevant (I think) code follows:
>
> echo "<p><form method=\"post\"
> action=\"$Relative/items.php?CA=$CatID&UID=$UID\"><select
> name=\"CatList\" size=\"1\">";
> while ($row = mysql_fetch_row($result))
> {
> $Cat=$row[0];
> $CatID=$row[1];
> echo "<option value=\"$row[0]\"> $row[0] </option>";
> }
> echo "</select><input type=\"submit\" name=\"Submit\"
> value=\"Go to
> Category\"></p></form>";
>
> It all works well except the variable $Cat is not showing in the action
> line. I have to get it to work with various layouts, but I am at an
> impasse. As a new PHP coder, I try to think it through, but this time I am
> stuck.
>
> Can anyone show me how to get the variable $Cat, inside the loop, to appear
> in the action line.
>
> Thanks
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>