Re: Tough Select List with multiple arrays
| From: | Angelko Krstanovic | Date: | Wed, 18 Oct 2000 23:20:14 +0000 |
| Subject: | Re: Tough Select List with multiple arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21003@lists.php.net to get a copy of this message | ||
phillip,
if i understand your question correctly, you are trying to
do dynamic selects. here is an example of a one way:
$id = $row['game_id'];
$select_name = 'selected'.$id;
${$select_name} = 'selected';
echo "
<select name=test>
<option name=1 $selected1> 1
<option name=2 $selected2> 2
<option name=3 $selected3> 3
<option name=4 $selected4> 4
</select>
";
the trick is in ${$select_name}. it instantiates a variable
whose name is contained in $select_name.
hope this helps.
-angelko
On Wed, 18 Oct 2000, Phillip S. Baker wrote:
> Okay this is a tough one that I am having trouble figuring out exactly.
>
> I have this SQL query and array.
> //Query to get the records of what games the player owns
> $game_query = mysql_query("SELECT game_id FROM games,members_games WHERE
> games.gameid=members_games.game_id AND member_id=$member_id GROUP BY
> game_id",$db);
> $game_result = mysql_fetch_array($game_query);
>
> So now I have a game_result array with numeric values in it.
>
> Then I have this form for a member to update their information. It has a
> list of all game titles.
>
> $query1 = "SELECT * FROM games";
> $game_query = mysql_query($query1);
> while($games = mysql_fetch_array($game_query))
> {
> /* Get the game titles and gameids for the check box list menu */
> $game_title = $games["title"];
> $gameid = $games["gameid"];
>
> /* Output a drop down menu list of all the games that The Grognards
> supports from the games table. */
> print("<INPUT TYPE=\"checkbox\" NAME=\"games[]\"
> VALUE=\"$gameid\">$game_title<BR>\n");
> }
>
> What I want to be able to add a bit of code to the second part so that
> if($game_result == "$gameid") { echo "checked"; }
> This way in the full list of games is a member has already listed that
> they have the game is automatically selected.
> Then the member can add or delete game titles from his profile.
>
> How do I do this?
>
> 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
>