Jump to content

[SOLVED] dynamic list order


182x

Recommended Posts

Hey guys, I was trying to get the list box to display the id numbers in ascending order however the code below does not work, just wondering how to fix it? thanks.

<?php
$g = "SELECT * FROM em ORDER BY iD ASC";
$q = mysql_query($g, $link_id) or die(mysql_error());

if (mysql_num_rows($q) > 0)
{
?>
<select name="d">
<?php
while($r = mysql_fetch_assoc($q))
{
?>
  <option value="<?php echo $r['Id']; ?>"><?php echo $r['Id']; ?></option>
<?php
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/
Share on other sites

Try this:

<?php
$g = "SELECT * FROM em ORDER BY id ASC";
$q = mysql_query($g, $link_id) or die(mysql_error());

if (mysql_num_rows($q) > 0){
echo'<select name="d">';
while($r = mysql_fetch_array($q)){
	echo'<option value="'.$r['id'].'">'.$r['id'].'</option>';
}
echo'</select>';
}
?>

 

If that doesn't work, could you explain what it is doing?

PC_Nerd that is true I have also had to re-write code to get the gremilin out.

 

182xx try this

<?php
$g = "SELECT Distinct Id FROM em ORDER BY Id ASC";
$q = mysql_query($g, $link_id) or die(mysql_error());
if (mysql_num_rows($q) > 0) {
echo "<select name='d'>";
while($r = mysql_fetch_assoc($q)) {
	echo "<option value='".$r['Id']."'>".$r['Id']."</option>";
}
             echo "</select>";
}
?>

 

 

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.