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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.