Crustyfur Posted May 21, 2007 Share Posted May 21, 2007 Hey, I want to call data from the db and display it in a dropdown and make the selected option match the value of the record called. It thats clear? query <?php } $result = $db->sql_query("SELECT * FROM ".$prefix."_fixtures a, ".$prefix."_teams b WHERE a.teamid = b.teamid AND fid ='$fid'"); if($row = $db->sql_fetchrow($result)) { ?> Best I can muster <?php echo "<select name=\"teamid\"> <option value=\"". $row[8] ."\">". $row[9] ."</option> </select>"; ?> As you can see all it does is display the one option and not everything in the list. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/52394-calling-dropdown-data-from-db/ Share on other sites More sharing options...
Dragen Posted May 21, 2007 Share Posted May 21, 2007 <?php } $result = $db->sql_query("SELECT * FROM ".$prefix."_fixtures a, ".$prefix."_teams b WHERE a.teamid = b.teamid AND fid ='$fid'"); if($row = $db->sql_fetchrow($result)) { echo '<select name="teamid">'; $i = '0'; while ($row = mysql_fetch_assoc($result)) { echo '<option value="'. $row[$i] .'">'. $row[$i] .'</option>'; $i++; } echo '</select>'; ?> EDIT: might be better using a foreach statement instead of while, but that should work Link to comment https://forums.phpfreaks.com/topic/52394-calling-dropdown-data-from-db/#findComment-258558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.