Jump to content

[SOLVED] Filter Results


Ell20

Recommended Posts

Hi,

 

I currently have a fixtures table which displays all the fixtures automatically in ascending order for date when the page is loaded.

 

This is exactly what I want to begin with but I would also like to add a filter (think this is right word?) so that the user could then order the results how they wish for example by Team Ascending or Date Descending or Venue Home.

 

Appreciate any help on adding this to my page.

 

Elliot

Link to comment
https://forums.phpfreaks.com/topic/80714-solved-filter-results/
Share on other sites

<?php

$filter = // filter goes here
$order = // Filter order ascending or descending

$query = mysql_fetch_array("SELECT * FROM table_1 ORDER BY $filter $border");

while($row=mysql_fetch_array($query)){

echo $row['item'];

}
?>

 

Explanation

 

Well, the first couple of lines I use 2 variables, one called $filter, and the next $order. $filter could be anything, it can be a drop down menu saying

 

- Filter by Teams

- Filter by Date

 

...etc

 

$order is the variable that which describes the order of the data shown, if he or she choses Filter by Teams Ascending, then it will show the teams from a -z, or if its a date, it will show from oldest to newest and vice versa.

 

 

Link to comment
https://forums.phpfreaks.com/topic/80714-solved-filter-results/#findComment-409373
Share on other sites

I kind of get what your saying but can the $filter and $order be drop down boxes that the user can select from?

 

Thanks

 

Yes, $filter and $order are suposed to be drop down menus

 

$filter

 

- Filter by Date

- Filter by Teams

 

$order

 

- Ascending

- Descending.

 

Please read my post from above, i added an explanation. :D

 

Your welcome btw.

Link to comment
https://forums.phpfreaks.com/topic/80714-solved-filter-results/#findComment-409377
Share on other sites

I think im nearly there but having a bit of trouble.

 

I want to preset the table so that when you view the page it orders by date ASC, then when you use the filter it filters by what ever you wish but im not really sure how to do that.

 

I have tried presetting the values like so:

 

$filter = 'date';

$order = 'ASC';

 

Then if they filter:

if (isset($_POST['submit6'])) {

$order = $order;

$filter = $filter;

}

 

The SQL here?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/80714-solved-filter-results/#findComment-409402
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.