View Single Post
  #1 (permalink)  
Old March 27th, 2007, 08:38 AM
gargamel gargamel is offline
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query was empty!!!!!!!!!!!!!!!!!!!!!!!!!

Ok, I spent hours looking for this error (query was empthy) and was not able to find anything wrong wiht my code! very frustrating!

I am using the "beginning PHP5, Apache, MySQL Web Development" book
the code is found on page 117

I would apprecitate if anyone can suggest ANYTHING.
My code is exactly the same as in book. Please take a look


<?php
//connect to the database
$link = mysql_connect("localhost", "root", "12345")
    or die(mysl_error());

//make sure we are using the right database
mysql_select_db("moviesite")
    or die(mysql_error());


$query = "SELECT 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;

$guery_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_name = $row['movie_name'];
    $movie_director = $row['movie_director'];
    $movie_leadactor = $row['movie_leadactor'];

//get director's name from poeple table
get_director();

//get actor's name from the people table
get_leadactor();


    $movie_details .=<<<EOD
    <tr>
     <td>$movie_name</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;

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



There it is. Either I am VERY WRONG or the book has a typo. :(

Hope you can help out
Reply With Quote