sorting using different columns

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toplet159
Forum Newbie
Posts: 10
Joined: Sun Jul 11, 2004 1:20 pm

sorting using different columns

Post by toplet159 »

Hi, i have looked eerywhere for what i need but i cant find anything,
what i am tyring to do is to be able to allow the user to click on a heading and it will sort the table by that heading ,
i have 3 headings | eventname | description | date |
help much appreciated thanks

Code: Select all

$result = mysql_query("SELECT * FROM eventslist WHERE id='$event'") or die(mysql_error()); 
         $num_rows = mysql_num_rows($result); 
         while ($u = mysql_fetch_array($result)) { 
            extract($u); 
            //$f_price = number_format($price,2); 
            echo" <table width="776" height="0" border="0" cellpadding="0" cellspacing="0">
      
  <tr>
    <td valign="top" class="eventshightlighttable" onmousedown="LmDown(this, 'menuentry_hovere')" onmouseup="LmUp('{$_SERVER['SCRIPT_NAME']}?id=$id')" onmouseover="LmOver(this, 'menuentry_hovere')" onmouseout="LmOut(this, 'menuentrye')">   
         <table border="0" cellpadding="0" cellspacing="0" ><table width="776" height="0" border="0" cellpadding="0" cellspacing="0" class="eventshighlighttable">
      <tr>
        <td><table width="776" border="0" cellspacing="0" cellpadding="0" class="eventstable">
          <tr>
            <td class="eventname">$eventname</td> 
                <td class="eventdescription">$description</td> 
                <td class="eventdate">$date</td> 	
				  </tr>
        </table></td>
      </tr>
    </table>
 
    </td>
  </tr>
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

If you were planning to sort it in order you will need to use ORDER BY within your original mysql query!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not pass the column to sort by through the url? And have mysql sort it for you?, or you could use [php_man]usort[/php_man] to sort it.. but you'd still have to fetch all the data from the table again..
Post Reply