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
Share on other sites

echo "<option value = '".$r['Id']."'>".$r['Id']."</option>\n";

 

i havent a clue what that might do to help, but i know that if i sometimes rewrite my code again, the error disapears.... its really weird

 

You were right that fixed it. Thanks :)

Link to comment
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?

Link to comment
Share on other sites

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>";
}
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.