Jump to content

[SOLVED] Nested SQL query help?


jhenary

Recommended Posts

I'm currently working on a project for a database class I'm taking. It's a simple database that displays movie showtimes and such. My problem is that when I try to nest a query inside the "while" of another query I only end up with one result. Here is the code, is what I'm trying possible?

 

$query2= "SELECT Movie_Name, MovieID, Screen FROM Movies".
	" INNER JOIN Showings ON Movies.Movie_ID = Showings.MovieID".
	" WHERE DAY(DateTime) = '$day'".
	" AND MONTH(DateTime) = '$month'".
	" AND TheaterID = '$theater'".
	" GROUP BY Screen ORDER BY Screen";
    
       $result = mysql_query($query2);
       while ($row = mysql_fetch_assoc ($result)) 
{                                           
        $movie = $row['Movie_Name'];
$movieid = $row['MovieID'];
$screen = $row['Screen'];
	echo"<A HREF=\"about.php?id=" . "$movieid" . "\" TARGET=\"_blank\">" . 
	"$movie" . "</a></br>";
   $query4 = "SELECT HOUR(DateTime) AS Hour, MINUTE(DATETIME) AS Minute FROM Showings".
" WHERE Screen = '$screen'";
   $result = mysql_query($query4);
       while ($row = mysql_fetch_assoc ($result)) 
{
$hour = $row['Hour'];
$minute = $row['Minute'];
	echo "("."$hour".":"."$minute";
	if ($minute<10){echo"0";}
	echo")";
}
}

 

What I'm trying to do is find all showings for a particular theater on a particular day and group those showings by the screen number they're playing on. For each line returned another query is run to display all show times for that day. Any help would be appreciated.

Link to comment
Share on other sites

yea make is  like this

 

$query2= "SELECT Movie_Name, MovieID, Screen FROM Movies".
	" INNER JOIN Showings ON Movies.Movie_ID = Showings.MovieID".
	" WHERE DAY(DateTime) = '$day'".
	" AND MONTH(DateTime) = '$month'".
	" AND TheaterID = '$theater'".
	" GROUP BY Screen ORDER BY Screen";
    
       $result = mysql_query($query2);
       while ($row = mysql_fetch_assoc ($result)) 
{                                           
        $movie = $row['Movie_Name'];
$movieid = $row['MovieID'];
$screen = $row['Screen'];
	echo"<A HREF=\"about.php?id=" . "$movieid" . "\" TARGET=\"_blank\">" . 
	"$movie" . "</a></br>";
   $query4 = "SELECT HOUR(DateTime) AS Hour, MINUTE(DATETIME) AS Minute FROM Showings".
" WHERE Screen = '$screen'";
   $result2 = mysql_query($query4);
$hour = $row['Hour'];
$minute = $row['Minute'];
       while ($row2 = mysql_fetch_assoc ($result2)) 
{
$hour = $row2['Hour'];
$minute = $row2['Minute'];
	echo "("."$hour".":"."$minute";
	if ($minute<10){echo"0";}
	echo")";
}
}

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.