Jump to content

Loop inside loop problem.


Mortenjan

Recommended Posts

Worked perfectly!

 

Thanks you very much mjdamato!

 

Regards Morten

 

To get the results to populate the date/times in the proper order add the date to the ORDER clause in the query:

$query="SELECT 
           movies.id, movies.name, movies.age_limit, movies.length_time, movies.filmweb, movies.picture, 
           date.id AS date_id, date, 
           time.id AS time_id, time
       FROM movies
       JOIN date ON movies.id = date.movie_id
       JOIN time ON date.id = time.date_id
       ORDER BY movies.name, date";

 

For the date issue, I left off a couple lines. Replace the WHILE loop with this code

while($movie = mysql_fetch_assoc($result))
{
  //Check for new movie
  if ($current_film_name != $movie['name'])
  {
       //New movie

       if($current_film_name != "")
       {
           //If not the first record, display the last movie
           displayMovie($m_name, $m_image, $m_age_limit, $m_length, $m_web, $m_dates, $m_times);
       }

       $current_film_name = $movie['name'];

       $m_name      = $movie['name'];
       $m_image     = $movie['picture'];
       $m_age_limit = $movie['age_limit'];
       $m_length    = $movie['length_time'];
       $m_web       = $movie['filmweb'];
       $m_dates     = "";
       $m_times     = "";
       $current_film_date = "";
}

   //Date/time data
   if ($current_film_date != $movie['date'])
   {
       //Different date from last record, show it
       $current_film_date = $movie['date'];
       $m_dates .= "{$movie['date']}<br>";
   }
   else
   {
       //Same date as last, line break
       $m_dates .= "<br>";
   }

//Time date
$m_times .= "{$movie['time']}<br>";
}

 

That should take care of it

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.