snowdog Posted August 28, 2006 Share Posted August 28, 2006 is there a way to sort by last name instaed of id without using an array. I want the Option boxes to be in alpabetical order but I am pulling from one database the id number and then going to get the info from another with that id.Here is the code:{ $query = "select * from grad_profile"; $result = mysql_query($query) or die('Query '.$query.' failed: ' . mysql_error());?><table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr> <td align="left" valign="top"> <img src="picts/spacer.gif" height="400" width="20" border="0"> </td> <td align="center" valign="top"> <table cellpadding="0" cellspacing="0" border="0" width="800"> <tr> <td align="left" valign="top"> <p align="center" class="just"><span class="title"><b>NEXT STEPS QUESTIONNAIRE</b></span></p> <br><br> <center> <table border=0 cellpadding=0 cellspacing=0 width="100%"> <tr> <td> <form method="post" name="userdata" action="grad_profile.php"> <select name="id"> <? while($row = mysql_fetch_object($result)) { $query = "select * from userdata where id = $row->id"; $result_user = mysql_query($query) or die('Query '.$query.' failed: ' . mysql_error()); $row_user = mysql_fetch_object($result_user); echo "<option value=\"$row->id\">$row_user->firstname $row_user->lastname</option>\n"; } ?> </select> <input type="hidden" name="choose" value="choose"> <input type="submit" value="Submit Info" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" class="button"> <input type=reset value="Clear Form" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" class="button"><br><br><br> </form> </td> </tr> </table> </center> </td> </tr> </table> </td> </tr></table>ThanksSnowdog Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 [code]<?php$query = "SELECT * FROM grad_profile LEFT JOIN userdata ON grad_profile.id = userdata.id ORDER BY userdata.lastname";$result = mysql_query($query) or die('Query '.$query.' failed: ' . mysql_error());while($row = mysql_fetch_object($result)) $select .= '<option value="' . $row['id'] . '">' . $row_user['firstname'] . ' ' . $row_user['lastname'] . '</option>' . "\n";}?><form method="post" name="userdata" action="grad_profile.php"> <select name="id"> <?php echo $select; ?> </select> <input type="hidden" name="choose" value="choose"> <input type="submit" value="Submit Info" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" class="button"> <input type=reset value="Clear Form" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" class="button"> </form>[/code] 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.