MikeDXUNL Posted July 30, 2008 Share Posted July 30, 2008 class MusicGames { protected $gameids = array('15', '1'); protected $game; public function searchGames() { echo '<select>'; foreach($this->gameids as $this->game) { $result = mysql_query("SELECT * FROM videogames WHERE gameid='".$this->game."") or die(mysql_error()); while($line = mysql_fetch_array($result)) { $this->m_gamename = $line['gamename']; echo '<option>'.$this->m_gamename.'</option>'; } } echo '</select>'; } } $search = new MusicGames; $search->searchGames(); this outputs nothing. am i grabbing the array numbers wrong? Link to comment https://forums.phpfreaks.com/topic/117285-drop-down-box/ Share on other sites More sharing options...
chacha102 Posted July 30, 2008 Share Posted July 30, 2008 I copied you code and had it reference the $gamenames array I made. Works fine. I believe its probably an error with the MySql Query; <?php class MusicGames { protected $gamenames = array( "1" => "test1", "2" => "test2", "3" => "test3", "4" => "test4", "5" => "test5", "6" => "test6", "7" => "test7", ); protected $gameids = array('6', '1'); protected $game; public function searchGames() { foreach($this->gameids as $this->game) { echo $this->gamenames[$this->game]; } } } $search = new MusicGames; $search->searchGames(); Link to comment https://forums.phpfreaks.com/topic/117285-drop-down-box/#findComment-603325 Share on other sites More sharing options...
trq Posted July 30, 2008 Share Posted July 30, 2008 There really is no need to loop through a series of game ids as it can be done in one query. <?php class MusicGames { protected $gameids = array(15,1); public function searchGames() { echo '<select>'; if ($result = mysql_query("SELECT gamename FROM videogames WHERE gameid IN('" . implode("'", $this->gameids) . "')")) { if (mysql_num_rows($result)) { while ($line = mysql_fetch_array($result)) { echo '<option>' . $line['gamename'] . '</option>'; } } } echo '</select>'; } } ?> I don't see much point in the whole class either but each to there own. I assume theres more to it than this. Link to comment https://forums.phpfreaks.com/topic/117285-drop-down-box/#findComment-603326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.