Reply
sorting by different columns
Old 08-06-2004, 11:20 PM sorting by different columns
Novice Talker

Posts: 5
Trades: 0
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

PHP Code:
$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> 
toplet is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 08-07-2004, 12:00 AM
Christopher's Avatar
Iced Cap

Posts: 3,113
Location: Toronto, Ontario
Trades: 0
You can have the headings link to the same page, but with a query string, say sort. For example: myscript.php?sort=date

I make an array of all valid sort types (so there's no tricky business if the user tries some sort crazyness like sort=crazyness )

PHP Code:
$sort 'eventname'// default
if(isset($_GET['sort']))
{
    
$valid = array('eventname''description''date'); // all other field names from your table

    
if(in_array($_GET['sort'], $valid))
        
$sort $_GET['sort';
}

$result mysql_query("SELECT * FROM eventslist WHERE id='$event' ORDER BY $sort") or die(mysql_error()); 
Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to sorting by different columns
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.09892 seconds with 13 queries