The is in mysql and is displayed using php, how do i assign sorting buttons (ascending and descending order) by clicking on the heading of the table...how is this achieved
The is in mysql and is displayed using php, how do i assign sorting buttons (ascending and descending order) by clicking on the heading of the table...how is this achieved
Read: http://jm.php.net/manual/en/function.sort.php
Sort with php.
|--- www.RealJamaicaEstate.com ™ ---|
Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
--- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com ™
Does any1 have an exiting script that shows how this is done and implemented?
It's nothing hard bro. Each header has a link that passes a variable via the url, something like http://www.mywebsite.com/index.php?sort=desc
Then in your script, you just check the sort value from the url and see if the value is desc or asc. If it's desc, you add the DESC to the end of your sql query. Same goes for ASC.
Sort = "SELECT field1, field2, field3 FROM TABLE ORDER BY field1 ASC"
|--- www.RealJamaicaEstate.com ™ ---|
Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
--- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com ™
I've been trying it but i seem 2 be off at some point...will post the code later today
Post the code, i'm sure we'll fix it
I got it workin thx 2 Sutra:
This is the query:
This is what the Column/list name shout look like:PHP Code:
function list($start=1,$rows=16)
{
$order = $_GET['order'];
$column = $_GET['sortby'];
if($column == 'info' && $order == 'asc')
{
$this->dao->fetch("SELECT * FROM item ORDER BY list ASC LIMIT ".$start.", ".$rows);
}
else if($column == 'info' && $order == 'desc')
{
$this->dao->fetch("SELECT * FROM list ORDER BY list DESC LIMIT ".$start.", ".$rows);
}
else
{
$this->dao->fetch("SELECT * FROM list ORDER BY timestamp DESC LIMIT ".$start.", ".$rows);
}
}
PHP Code:
<a href=\"".$_SERVER['PHP_SELF']."?order=asc&sortby=info&view=table&rownum=".($rownum)."\">Column Name ^</a>
<a href=\"".$_SERVER['PHP_SELF']."?order=desc&sortby=info&view=table&rownum=".($rownum)."\">Column Name v</a>
cool...
what are you using it for, desktop app or web app?
|--- www.RealJamaicaEstate.com ™ ---|
Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
--- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com ™