Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dose anyone know how to do this

New Here ,
Aug 18, 2006 Aug 18, 2006
Im trying to filter a mysql recordset dynamically like the following site:
Click Here
Any help in appriciated.
TOPICS
Server side applications
332
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2006 Aug 19, 2006
jlw12689 wrote:
> Im trying to filter a mysql recordset dynamically like the following
> site:

Rather than showing us a site where it works, show us how far *you've* got
on it and provide some specific details on what you want to do.

Regards,

Pete.
--
Peter Connolly
http://www.acutecomputing.co.uk
Derby
UK
Skype ID: acutecomputing


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2006 Aug 19, 2006
I am trying to make a dynamic table that the user can sort through a form on my web site. Example: Sort by order date or by the expiring date.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 20, 2006 Aug 20, 2006
LATEST
Hi jlw,
Your code must be like this now:

mysql_select_db($database_yourconnect, $yourconnect);
$query_carList = "SELECT * FROM cars";
$carList = mysql_query($query_carList, $yourconnect) or die(mysql_error());
$row_carList = mysql_fetch_assoc($carList);
$totalRows_carList = mysql_num_rows($carList);

Than in code view;
Write these before your query;

swtich ($_GET['order']){
case 'date':
$order = "date";
break;
case 'expiredate':
$order = "expiredate":
break;
default:
$order = "id";
}

and in your sql query add this: Order by '$order'

So finally you will have this:

swtich ($_GET['order']){
case 'date':
$order = "date".$_GET['sort'];
break;
case 'expiredate':
$order = "expiredate".$_GET['sort'];
break;
default:
$order = "id".$_GET['sort'];
}
mysql_select_db($database_yourconnect, $yourconnect);
$query_carList = "SELECT * FROM cars ORDER BY '$order'";
$carList = mysql_query($query_carList, $yourconnect) or die(mysql_error());
$row_carList = mysql_fetch_assoc($carList);
$totalRows_carList = mysql_num_rows($carList);

Your links will be like this:
Order By Date:
<a href="resultspage.php?order=date&sort=asc">Ascending</a>
<a href="resultspage.php?order=date&sort=desc">Descending</a>

Order by Expire:
<a href="resultspage.php?order=expiredate&sort=asc">Ascending</a>
<a href="resultspage.php?order=expiredate&sort=desc">Descending</a>

Change your variable names with the example codes. If you will use form to retrieve results use $_POST instead $_GET
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines