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

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.