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 } } ?> Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/ Share on other sites More sharing options...
jvrothjr Posted July 18, 2007 Share Posted July 18, 2007 is the field name Id or iD Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301303 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 Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301309 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 Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301319 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 Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301322 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. Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301327 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 Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301332 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? Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301334 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/60564-solved-dynamic-list-order/#findComment-301343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.