Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | 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 Display Modes
  #1 (permalink)  
Old March 24th, 2007, 05: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;
?>


Reply With Quote
  #2 (permalink)  
Old March 27th, 2007, 12:17 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
 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

Reply With Quote
  #3 (permalink)  
Old March 28th, 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

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!:)

Reply With Quote
  #4 (permalink)  
Old March 29th, 2007, 12:37 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
 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

Reply With Quote
Reply


Thread Tools
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
Problems with chapter 1 macuser BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 2 April 2nd, 2009 01:39 PM
Problems with Example in Chapter 6 elly BOOK: Professional Crystal Reports for VS.NET 0 March 31st, 2008 04:39 PM



All times are GMT -4. The time now is 05:37 PM.


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