Jump to content

Sorting by


snowdog

Recommended Posts

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

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



                  </form>
[/code]
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.