182x Posted July 18, 2007 Share Posted July 18, 2007 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 } } ?> Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted July 18, 2007 Share Posted July 18, 2007 is the field name Id or iD Quote Link to comment Share on other sites More sharing options...
182x Posted July 18, 2007 Author Share Posted July 18, 2007 sorry that was a typo when changing variables its Id Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted July 18, 2007 Share Posted July 18, 2007 could be an issue with the field type. Is the field Char or Int Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted July 18, 2007 Share Posted July 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
182x Posted July 18, 2007 Author Share Posted July 18, 2007 could be an issue with the field type. Is the field Char or Int The type is varchar, does that make a difference. I pretty new to all this. Quote Link to comment Share on other sites More sharing options...
182x Posted July 18, 2007 Author Share Posted July 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted July 18, 2007 Share Posted July 18, 2007 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? Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted July 18, 2007 Share Posted July 18, 2007 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.