Re: Tough Select List with multiple arrays

From: Date: Thu, 19 Oct 2000 00:08:04 +0000
Subject: Re: Tough Select List with multiple arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-21020@lists.php.net to get a copy of this message
This appears to have worked just fine. However I am not quite clear on what happened here. Can you please walk me through what is happening in each step? Phillip At 04:52 PM 18-10-00 -0700, Angelko Krstanovic wrote:
will this work 4u:
$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);
while ($game_result = mysql_fetch_array($game_query)) { $all_games[$game_result['game_id']] = 1; }
$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\"
");
      if($all_games[$gameid]) { echo "checked"; }
      echo ">$game_title<BR>\n");
}
-angelko On Wed, 18 Oct 2000, Phillip S. Baker wrote: This is kind of it, but the trick here is that the select list is also dynamically generated from a set of values in a database. Would it still be basically the same? Phillip At 04:20 PM 18-10-00 -0700, Angelko Krstanovic wrote:
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
-- 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 -- 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

« previous php.general (#21020) next »