p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 (http://p2p.wrox.com/forumdisplay.php?f=160)
-   -   Yet more Chapter 4 problems (http://p2p.wrox.com/showthread.php?t=55809)

Putter March 24th, 2007 04:23 PM

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



TheDudeTux March 27th, 2007 11:17 AM

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


Putter March 28th, 2007 03:23 PM

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


TheDudeTux March 28th, 2007 11:37 PM

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



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

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