Wrox Programmer Forums
| 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 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 March 24th, 2007, 04:23 PM
Registered User
 
Join Date: Mar 2007
Location: Hull, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Yet more Chapter 4 problems

Can anyone help?...I am nearing the end of my rope!!!

I have adapted the code from pages 111 - 116 for my snooker teams database and cannot get the table to populate with data from my hosted database table. The table header comes back OK but there are no main table cells for the data to populate. I want to get to the stage where I can use links in the table to jump to other pages but cannot get past this hurdle. Can anyone please help ? My code looks like this;

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

$query = ("SELECT team_id, team_name, division_id FROM tbl_teams");
$result = mysql_query($query, $link)
or die(mysql_error());
$num_teams = mysql_num_rows($result);

$table_header = <<<EOD
<h2><center>Teams Database</center></h2>
<table width="70%" border="1" cellpadding="2"
       cellspacing="2" align="center">
  <tr>
    <th>Team ID</th>
    <th>Team Name</th>
    <th>Division ID</th>
  </tr>
</table>
EOD;

$table_details = '';
while ($row = mysql_fetch_array($result)) {
  $team_id = $row['team_id'];
  $team_name = $row['team_name'];
  $division_id = $row['division_id'];

  $table_details .=<<<EOD
  <tr>
   <td>$team_id</td>
   <td>$team_name</td>
   <td>$division_id</td>
  </tr>
EOD;
}

$table_details .=<<<EOD
<tr>
   <td>Total :$num_teams Teams</td>
  </tr>
EOD;

$table_footer = "</table>";

$teams =<<<TEAMS
  $table_header
  $table_details
  $table_footer
TEAMS;

  echo "There are $num_teams Teams in our database";
  echo $teams;
?>


  #2 (permalink)  
Old March 27th, 2007, 11:17 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Putter
 Can anyone help?...I am nearing the end of my rope!!!

I have adapted the code from pages 111 - 116 for my snooker teams database and cannot get the table to populate with data from my hosted database table. The table header comes back OK but there are no main table cells for the data to populate. I want to get to the stage where I can use links in the table to jump to other pages but cannot get past this hurdle. Can anyone please help ? My code looks like this;

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

$query = ("SELECT team_id, team_name, division_id FROM tbl_teams");
$result = mysql_query($query, $link)
or die(mysql_error());
$num_teams = mysql_num_rows($result);

$table_header = <<<EOD
<h2><center>Teams Database</center></h2>
<table width="70%" border="1" cellpadding="2"
       cellspacing="2" align="center">
  <tr>
    <th>Team ID</th>
    <th>Team Name</th>
    <th>Division ID</th>
  </tr>
</table>
EOD;

$table_details = '';
while ($row = mysql_fetch_array($result)) {
  $team_id = $row['team_id'];
  $team_name = $row['team_name'];
  $division_id = $row['division_id'];

  $table_details .=<<<EOD
  <tr>
   <td>$team_id</td>
   <td>$team_name</td>
   <td>$division_id</td>
  </tr>
EOD;
}

$table_details .=<<<EOD
<tr>
   <td>Total :$num_teams Teams</td>
  </tr>
EOD;

$table_footer = "</table>";

$teams =<<<TEAMS
  $table_header
  $table_details
  $table_footer
TEAMS;

  echo "There are $num_teams Teams in our database";
  echo $teams;
?>


 Hi, I don't have your database so I can't really debug it too much..to see what works or what doesn't. But I did notice one of your lines syntax was like this:

$table_header = <<<EOD

You might want to make it like this $table_header =<<<EOD
in order to take out the space.. Let me know if it works. Take care!
-TheDudeTux

  #3 (permalink)  
Old March 28th, 2007, 03:23 PM
Registered User
 
Join Date: Mar 2007
Location: Hull, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Dude, Thanks for taking the time to review my code. I actually managed to get this to work only last evening. I think more by accident than anything else. But...you will be pleased to know that the correction you spotted was, I believe, part of the problem.

Many thanks

A fan!:)

  #4 (permalink)  
Old March 28th, 2007, 11:37 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Putter
 Hey Dude, Thanks for taking the time to review my code. I actually managed to get this to work only last evening. I think more by accident than anything else. But...you will be pleased to know that the correction you spotted was, I believe, part of the problem.

Many thanks

A fan!:)

haha hey!! Thanks a lot! :-) I'm glad it worked out for you. Sorry I didn't get to you faster. It's good you didn't stop or give up. Keep Coding... Take Care
-TheDudeTux



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with chapter 1 macuser BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 2 April 2nd, 2009 12:39 PM
Problems with Example in Chapter 6 elly BOOK: Professional Crystal Reports for VS.NET 0 March 31st, 2008 03:39 PM





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