Jump to content

Calling dropdown data from db


Crustyfur

Recommended Posts

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

 <?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.