Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2006, 11:50 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Solution: Chapter 4, Table 2 Problems

Okay so this is so strange and it happened by accident but like a lot of others I was stuck on creating Table2 in Chapter 4. I mistakenly typed into my URL, this: http://localhost/table2.php
AND IT WORKED! Without the "\" it continued to show up blank but adding that "\" at the end made it display. This is so strange, but I kept checking and rechecking my code and it was all correct, I had no spaces after my EOD statements or anything. And this fixed it. Perhaps it will help others as well. This is what my code looks like:

<?php
$link = mysql_connect("localhost","root","password") or die(mysql_error());
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;

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

  get_director();

  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;
?>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Solution to Chapter 20 Spasticus BOOK: Ivor Horton's Beginning Visual C++ 2005 1 January 26th, 2008 08:12 AM
problems with the reviews table in chapter 4 derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 15th, 2007 03:58 AM
Solution: Chapter 4, Table 2 Problems amenne20 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 September 22nd, 2006 11:48 AM
solution 1 in exercises in chapter 6 juan_forum BOOK: Beginning Java 2 0 September 16th, 2005 11:03 AM



All times are GMT -4. The time now is 08:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.