Jump to content


Photo

Sorting by


  • Please log in to reply
1 reply to this topic

#1 snowdog

snowdog
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 28 August 2006 - 08:27 PM

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">&nbsp;<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>

Thanks

Snowdog

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 08:47 PM

<?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">&nbsp;<input type=reset value="Clear Form" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" class="button">



                  </form>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users