Page 1 of 1

sorting using different columns

Posted: Fri Aug 06, 2004 10:25 pm
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>

Posted: Fri Aug 06, 2004 10:27 pm
by Joe
If you were planning to sort it in order you will need to use ORDER BY within your original mysql query!

Posted: Fri Aug 06, 2004 10:30 pm
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..