Jump to content

Filtering results into boxes?


Andrew R

Recommended Posts

Hi there

 

I have a table called routes.  In this table I have a column called days which is in the format, MON-TUES-WED-THU-FRI-SAT-SUN.  In my html I have 7 html boxes for the results to go into.  The query I am using to search the table is SELECT * FROM routes where departure = '$a' && arrival = '$b'

 

What I want to do is sort the results into the correct box.  For example all the Mon routes would go into the Monday html box.  How would I go about doing this?  Would I create a number of arrays? 

 

I guess an inefficient way would be to create 7 queries but surely there’s a more dynamic way?

 

Many thanks :)

 

Link to comment
https://forums.phpfreaks.com/topic/135571-filtering-results-into-boxes/
Share on other sites

<?php
$query = "SELECT * FROM routes where departure = '$a' && arrival = '$b'";
$result = mysql_query($query);
$routes = array();
while ($row = mysql_fetch_assoc($result)) {
    $routes[$row['day']][] = $row;
}
print_r($routes);
?>

 

So you have an array called $routes with everything nicley ordered in it.

 

all you need to do is a foreach loop in each html box

 

foreach($routes[MON] as $mon)

{

    //output stuff here

    echo $mon;

}

 

foreach($routes[TUE] as $tue)

{

    //output stuff here

    echo $tue;

}

 

somthing like that

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.