Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 13th, 2004, 12:30 PM
Registered User
 
Join Date: May 2004
Location: London, , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query was empty

I am working through the examples in Chapter 4 and everything was great until the last part, displaying the reviews. Every time I click through to movie_details.php I get a blank page apart from the message - Query was empty.

I have checked everything with the code download and it all seems fine. So I'm not sure what has gone wrong.

Can anyone help me with this please. I'm sure it is something obvious, but I just can't see it.

Keiran
  #2 (permalink)  
Old May 24th, 2004, 06:13 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Can you post some relevant snips of the code?

Sorry, I don't have the book and am unwilling to download the source code ;).

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
  #3 (permalink)  
Old June 24th, 2004, 07:38 PM
Registered User
 
Join Date: Jun 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Keiran,

How did you manage to solve this problem back in May? I'm having the same problem....

Steve

Quote:
quote:Originally posted by keiran
 I am working through the examples in Chapter 4 and everything was great until the last part, displaying the reviews. Every time I click through to movie_details.php I get a blank page apart from the message - Query was empty.

I have checked everything with the code download and it all seems fine. So I'm not sure what has gone wrong.

Can anyone help me with this please. I'm sure it is something obvious, but I just can't see it.

Keiran
  #4 (permalink)  
Old June 24th, 2004, 07:42 PM
Registered User
 
Join Date: Jun 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the downloaded code for the parent and child php pages that produces the error message of an empty mysql query. Can someone please help me get past this....?

First, the parent page:

<?php
$link = mysql_connect("localhost","","") or die(mysql_error());
     mysql_select_db("wiley") or die (mysql_error());

$query = "SELECT
     movie_id,
     movie_name,
     movie_director,
     movie_leadactor
     FROM
     movie";

     $result = mysql_query($query,$link) or die(mysql_error());
     $num_movies = mysql_num_rows($result);


$movie_header=<<<EOD
     <h2><center>Movie Review Database</center></h2>
     <table width='70%' border='1' cellpadding='2'
      cellspacing='2' align='center'>
          <tr>
               <th>Movie Title</th>
               <th>Movie Director</th>
               <th>Movie Lead Actor</th>
          </tr>

EOD;

function get_director() {
     global $movie_director;
     global $director;

     $query_d = "SELECT people_fullname
          FROM people
          WHERE people_id='$movie_director' ";
     $results_d = mysql_query($query_d) or die(mysql_error());
     $row_d = mysql_fetch_array($results_d);
     extract ($row_d);
     $director = $people_fullname;
}

function get_leadactor() {
     global $movie_leadactor;
     global $leadactor;

     $query_a = "SELECT people_fullname
          FROM people
          WHERE people_id='$movie_leadactor'";
     $results_a = mysql_query($query_a) or die(mysql_error());
     $row_a = mysql_fetch_array($results_a);
     extract ($row_a);
     $leadactor = $people_fullname;
}

while($row = mysql_fetch_array($result))
{
     $movie_id = $row['movie_id'];
     $movie_name = $row['movie_name'];
     $movie_director = $row['movie_director'];
     $movie_leadactor = $row['movie_leadactor'];

     //get director's name from people table
     get_director($movie_director);

     //get lead actor's name from people table
     get_leadactor($movie_leadactor);

     $movie_details .=<<<EOD
     <tr>
          <td><a href='movie_details3.php?movie_id=$movie_id'title=
'Find out more about $movie_name'>$movie_name</a></td>
          <td>$director</td>
          <td>$leadactor</td>
     </tr>
EOD;
     }


$movie_details .=<<<EOD
<tr>
     <td>Total :$num_movies Movies</td>
</tr>
EOD;

$movie_footer ="</table>";

$movie =<<<MOVIE
               $movie_header
               $movie_details
               $movie_footer
MOVIE;

     print "There are $num_movies movies in our database";
     print $movie;
?>

...and now the child code:

<?php
$link = mysql_connect("localhost","","")
 or die(mysql_error());
     mysql_select_db("wiley") or die (mysql_error());

/* Function to calculate if a movie made a profit,
loss or broke even */
function calculate_differences($takings,$cost)
{
     $difference = $takings - $cost;

     if($difference <0)
     {
          $difference = substr($difference,1);
          $font_color ='red';
          $profit_or_loss = "$".$difference."m";
     }elseif($difference >0){
          $font_color ='green';
          $profit_or_loss = "$".$difference."m";
     }else{
          $font_color ='blue';
          $profit_or_loss = "Broke even";
     }
     return "".$profit_or_loss."";
}

/* Function to get the director's name from the people table */
function get_director() {
     global $movie_director;
     global $director;

     $query_d = "SELECT people_fullname
          FROM people
          WHERE people_id='$movie_director' ";
     $results_d = mysql_query($query_d) or die(mysql_error());
     $row_d = mysql_fetch_array($results_d);
     extract ($row_d);
     $director = $people_fullname;
}

/* Function to get the lead actor's name from the people table */
function get_leadactor() {
     global $movie_leadactor;
     global $leadactor;

     $query_a = "SELECT people_fullname
          FROM people
          WHERE people_id='$movie_leadactor'";
     $results_a = mysql_query($query_a) or die(mysql_error());
     $row_a = mysql_fetch_array($results_a);
     extract ($row_a);
     $leadactor = $people_fullname;
}

function generate_ratings($review_rating)
{
     for($i=0;$i<$review_rating;$i++)
     {
          $movie_rating .= "<img src='thumbsup.gif'> ";
     }
     return $movie_rating;
}

$movie_query = "SELECT
               *
         FROM
                 movie
         WHERE
                  movie_id ='".$_GET['movie_id']."'";

$movie_result = mysql_query($query,$link) or die(mysql_error());

$movie_table_headings=<<<EOD
     <tr>
          <th>Movie Title</th>
          <th>Year of Release</th>
          <th>Movie Director</th>
          <th>Movie Lead Actor</th>
          <th>Movie Running Time</th>
          <th>Movie Health</th>
     </tr>
EOD;

$review_table_headings=<<<EOD
     <tr>
          <th>Date of Review</th>
          <th>Review Title</th>
          <th>Reviewer Name</th>
          <th>Movie Review Comments</th>
          <th>Rating</th>
     </tr>
EOD;

while($row = mysql_fetch_array($movie_result))
{
     $movie_name = $row['movie_name'];
     $movie_director = $row['movie_director'];
     $movie_leadactor = $row['movie_leadactor'];
     $movie_year = $row['movie_year'];
     $movie_running_time = $row['movie_running_time']." mins";
     $movie_takings = $row['movie_takings'];
     $movie_cost = $row['movie_cost'];

     //get director's name from people table
     get_director($movie_director);

     //get lead actor's name from people table
     get_leadactor($movie_leadactor);

}

while($review_row = mysql_fetch_array($review_result))
{
     $review_flag =1;
     $review_title[] = $review_row['review_name'];
     $reviewer_name[] = ucwords($review_row['review_reviewer_name']);
     $review[] = $review_row['review_comment'];
     $review_date[] = $review_row['review_date'];
     $review_rating[] = generate_ratings($review_row['review_rating']);
}

$review_query = "SELECT
                         *
               FROM
                         reviews
               WHERE
                          review_movie_id ='".$_GET['movie_id']."'
               ORDER BY
                          review_date DESC";

$review_result = mysql_query($review_query,$link) or die(mysql_error());

$i=0;
while($i<sizeof($review))
{
     $review_details .=<<<EOD
     <tr>
          <td width='15%' valign='top' align='center'>$review_date[$i]</td>
          <td width='15%' valign='top'>$review_title[$i]</td>
          <td width='10%' valign='top'>$reviewer_name[$i]</td>
          <td width='50%' valign='top'>$review[$i]</td>
          <td width='10%' valign='top'align='center'>$review_rating[$i]</td>
     </tr>
EOD;
     $i++;
}

$movie_health =
     calculate_differences($movie_takings,$movie_cost);
$page_start =<<<EOD
<HTML>
     <head>
          <title>Details and Reviews for: $movie_name</title>
     </head>
     <body>
EOD;
$movie_details =<<<EOD
<table width='70%' border='0' cellspacing='2' cellpadding='2' align='center'>
     <tr>
          <th colspan='6'>[u]<h2>$movie_name: Details</h2></u></th>
     </tr>
          $movie_table_headings
     <tr>
          <td width='33%' align='center'>$movie_name</td>
          <td align='center'>$movie_year</td>
          <td align='center'>$director</td>
          <td align='center'>$leadactor</td>
          <td align='center'>$movie_running_time</td>
          <td align='center'>$movie_health</td>
     </tr>
</table>
<br />
<br />
EOD;

if($review_flag)
{
     $movie_details .=<<<EOD
          <table width='95%' border='0' cellspacing='2'
            cellpadding='20' align='center'>
          $review_table_headings
          $review_details
     </table>
EOD;
}
$page_end =<<<EOD
     </body>
</HTML>
EOD;
$detailed_movie_info =<<<EOD
     $page_start
     $movie_details
     $page_end
EOD;

echo $detailed_movie_info;
mysql_close();
?>

Quote:
quote:Originally posted by richard.york
 Can you post some relevant snips of the code?

Sorry, I don't have the book and am unwilling to download the source code ;).

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::

  #5 (permalink)  
Old August 24th, 2004, 01:36 PM
Registered User
 
Join Date: Aug 2004
Location: Albuquerque, NM, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nmwebs
Default

I'm currently receiving the same thing. I even had it dumped the debug info, and here's what I get:

Array
(
)

Query was empty

PLEASE HELP

  #6 (permalink)  
Old September 1st, 2004, 11:44 AM
Registered User
 
Join Date: Aug 2004
Location: Albuquerque, NM, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nmwebs
Default

I'm about to get knocked down to page 2, so I had to post a reply. Was nobody able to help Steve? Has nobody else received this same issue, or is it only Steve and I?
  #7 (permalink)  
Old September 1st, 2004, 02:33 PM
Friend of Wrox
 
Join Date: Jun 2004
Location: Fairfield, Iowa, USA.
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Man I spent like 30 minutes trying to figure this one out. Look for the lines that say:
Code:
1)$movie_query = "SELECT * FROM movie WHERE
movie_id ='".$_GET['movie_id']."'";
2)$movie_result = mysql_query($query,$link) or die(mysql_error());
If you pay careful atention to the second line, you will notice that you are using the value of the variable $query as a parameter for the mysql_query command. Now you might just be wondering what is wrong with that. Well the problemm is that the variable $query hasn't been defined hence the message. You should be pasing $movie_query instead of $query. Just change that and it should work.

Christian
  #8 (permalink)  
Old September 1st, 2004, 07:10 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used the exact same code (except i changed $query to $movie_query) and i get these errors


Warning: extract(): First argument should be an array in /home/doesitro/public_html/table2.php on line 38

Warning: extract(): First argument should be an array in /home/doesitro/public_html/table2.php on line 51

also it says There are 4 movies in our database, there should i believe only be 3.


any help would be much appreciated.

  #9 (permalink)  
Old September 1st, 2004, 07:14 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry for double post this is the code around line 38-----------------

function get_director() {
     global $movie_director;
     global $director;

     $query_d = "SELECT people_fullname
          FROM people
          WHERE people_id='$movie_director' ";
     $results_d = mysql_query($query_d) or die(mysql_error());
     $row_d = mysql_fetch_array($results_d);
     extract ($row_d);
     $director = $people_fullname;
}

--------------this is the code around line 51----------------

function get_leadactor() {
     global $movie_leadactor;
     global $leadactor;

     $query_a = "SELECT people_fullname
          FROM people
          WHERE people_id='$movie_leadactor'";
     $results_a = mysql_query($query_a) or die(mysql_error());
     $row_a = mysql_fetch_array($results_a);
     extract ($row_a);
     $leadactor = $people_fullname;
}

  #10 (permalink)  
Old September 1st, 2004, 10:10 PM
Friend of Wrox
 
Join Date: Jun 2004
Location: Fairfield, Iowa, USA.
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default

These 2 functions assumes there is always something to be returned, which if you followed the exercises the book there should always be.
If you notice the errors they are actually warning which will not halt your script; In order to make this warning disappear just make sure you check to see if the mysql_fetch_array actually fetched something.The first function should be something like this:
Code:
function get_director() {
     global $movie_director;
     global $director;

     $query_d = "SELECT people_fullname
          FROM people
          WHERE people_id='$movie_director' ";
     $results_d = mysql_query($query_d) or die(mysql_error());
     $row_d = mysql_fetch_array($results_d);
     if (!empty($row_d) {
     extract ($row_d);
     $director = $people_fullname;
     }
     else $director='';//I initiate this variable so that you don't get a warning when I try to use this variable
}
I think this should do the trick

Christian




Similar Threads
Thread Thread Starter Forum Replies Last Post
Inner empty tag jdzsolt XSLT 2 August 8th, 2008 03:49 PM
Query was empty!!!!!!!!!!!!!!!!!!!!!!!!! gargamel BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 5 March 27th, 2007 11:32 AM
why my variable is empty? Joann Beginning VB 6 2 March 19th, 2007 04:08 PM
Is the clipboard empty? achinfish Excel VBA 1 July 15th, 2006 04:34 PM
check if empty hosefo81 Javascript How-To 12 March 9th, 2004 08:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.