www.webdeveloper.com
Results 1 to 2 of 2

Thread: Displaying data similar to WHILE loop but not in table format.

  1. #1
    Join Date
    May 2008
    Posts
    14

    Displaying data similar to WHILE loop but not in table format.

    I have a query that joins two tables and sorts by date, name and then time.



    time_id , movie_title , movie_time , movie_date , movie_id , movie_rating , movie_duration
    1 , Red , 18:00:00 , 12/31/13 , 1 , R , 2h 31m
    2 , Red , 21:00:00 , 12/31/13 , 1 , R , 2h 31m
    3 , Blue , 14:00:00 , 12/31/13 , 2 , PG-13 , 1h 15m
    4 , Green , 18:30:00 , 12/31/13 , 3 , G , 1h 25m
    5 , Red , 18:30:00 , 12/30/13 , 1 , R , 2h 31m
    6 , Blue , 18:30:00 , 12/30/13 , 2 , PG-13 , 1h 15m
    7 , Green , 18:30:00 , 12/30/13 , 3 , G , 1h 25m



    I am able to use a while loop to display the table but can't figure out to achieve a similar output.


    Only movies for current date:
    <table>
    <tr>
    <td>
    Movie title 1 - Movie Rating
    </td>
    <td>
    Movie Time 1 . <p>
    Movie Time 2<p>
    Movie.......
    </td>
    </tr>
    <tr>
    <td>
    Movie title 2 - Movie Rating
    </td>
    <td>
    Movie Time 1<p>
    Movie Time 2<p>
    Movie.......
    </td>
    </tr>
    </table>


    I assume a separate WHILE loop would be needed for the Movie times. I'm clueless what to search for to build the logic to search out next unique movie title then return movie title and other data until the next unique movie title. If it sound like I have no clue what I'm talking about. It probably true. What do I need to search for?


    Thank you

  2. #2
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    Just to clarify you're trying to display the times for the current date only?

    1 , Red , 18:00:00 , 12/31/13 , 1 , R , 2h 31m
    2 , Red , 21:00:00 , 12/31/13 , 1 , R , 2h 31m
    3 , Blue , 14:00:00 , 12/31/13 , 2 , PG-13 , 1h 15m
    4 , Green , 18:30:00 , 12/31/13 , 3 , G , 1h 25m

    So you essentially want (for the one date)
    12/31/13 Red @ 18:00:00, 21:00:00 ?

    If that's the case, you need to rewrite your sql to group_concat time based on the same day. Then your data would return something like

    1,Red,"18:00:00,21:00:00", 12/31/13, 1, R, 2H 31m
    2 , Blue , 14:00:00 , 12/31/13 , 2 , PG-13 , 1h 15m
    3 , Green , 18:30:00 , 12/31/13 , 3 , G , 1h 25m

    Then in your foreach or while loop, you'd explode(",",$time); and then you'd have $time[0] = "18:00:00" and $time[1] = "21:00:00";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles