displaying information in MyQL into an HTML table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Count your braces. You have an extra one somewhere.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

I took out a brace that looked like it didn't belong, but that didn't fix the problem.

I now have:

Code: Select all

<?php
ini_set('display_errors', 'On')
error_reporting(E_ALL);
//db connect and select 
$db_name="bruceg_friends-family"; 
$table_name ="address_book"; 
$connection = @mysql_connect("208.65.62.13", "bruceg_webmaster", "phoenix") 
or die (mysql_error()); 
$db = @mysql_select_db($db_name, $connection) or die (mysql_error()); 

$result=mysql_query ("select * from address_book"); 
$resultCount = mysql_num_rows($result); 

if ($resultCount > 0)   {  // make sure we have data to display 

echo<<<TABLETOP 
<table border="0" cellspacing="0" cellpadding="10" align="center"> 
<tr> 
<th>id</th> 
    <th>Name</th> 
    <th>address1</th> 
    <th>address2</th> 
    <th>zip</th> 
    <th>primary phone</th> 
    <th>Seconday phone</th> 
    <th>notes</th> 
   </tr> 
TABLETOP; 
while ($row = mysql_fetch_assoc($result)) {  // Display the data from mysql 
echo<<<TABLEDATA 
  <tr> 
    <td>{$row['id']}</td> 
    <td>{$row['Name']</td> 
    <td>{$row['address1']</td> 
    <td>{$row['addres2']</td> 
    <td>{$row['zip']</td> 
    <td>{$row['primary_phone']</td> 
    <td>{$row['2ndary_phone']</td> 
    <td>{$row['notes']</td> 
  </tr> 
TABLEDATA; 

}  //  End while 

echo "</table>"; 

}  // End if 


?>
if someone has a php debugging program, they could test this on, I would greatly appreciate it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're missing a semicolon.
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

bruceg wrote:I took out a brace that looked like it didn't belong, but that didn't fix the problem.

I now have:

Code: Select all

<?php
ini_set('display_errors', 'On')
error_reporting(E_ALL);
//db connect and select 
$db_name="bruceg_friends-family"; 
$table_name ="address_book"; 
$connection = @mysql_connect("208.65.62.13", "bruceg_webmaster", "phoenix") 
or die (mysql_error()); 
$db = @mysql_select_db($db_name, $connection) or die (mysql_error()); 

$result=mysql_query ("select * from address_book"); 
$resultCount = mysql_num_rows($result); 

if ($resultCount > 0)   {  // make sure we have data to display 

echo<<<TABLETOP 
<table border="0" cellspacing="0" cellpadding="10" align="center"> 
<tr> 
<th>id</th> 
    <th>Name</th> 
    <th>address1</th> 
    <th>address2</th> 
    <th>zip</th> 
    <th>primary phone</th> 
    <th>Seconday phone</th> 
    <th>notes</th> 
   </tr> 
TABLETOP; 
while ($row = mysql_fetch_assoc($result)) {  // Display the data from mysql 
echo<<<TABLEDATA 
  <tr> 
    <td>{$row['id']}</td> 
    <td>{$row['Name']}</td> 
    <td>{$row['address1']}</td> 
    <td>{$row['addres2']}</td> 
    <td>{$row['zip']}</td> 
    <td>{$row['primary_phone']}</td> 
    <td>{$row['2ndary_phone']}</td> 
    <td>{$row['notes']}</td> 
  </tr> 
TABLEDATA; 

}  //  End while 

echo "</table>"; 

}  // End if 


?>
if someone has a php debugging program, they could test this on, I would greatly appreciate it.
I forgot the second half of the curly braces for the $row data inside the while loop. Try it now.

Also, is there actual data in the table? if not, that you'll see nothing because of the if statement.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

I added the missing ; and this is what I now have. Still a blank page :-(

Code: Select all

<?php
ini_set('display_errors', 'On')
error_reporting(E_ALL);
//db connect and select 
$db_name="bruceg_friends-family"; 
$table_name ="address_book"; 
$connection = @mysql_connect("208.65.62.13", "bruceg_webmaster", "phoenix"); 
or die (mysql_error()); 
$db = @mysql_select_db($db_name, $connection) or die (mysql_error()); 

$result=mysql_query ("select * from address_book"); 
$resultCount = mysql_num_rows($result); 

if ($resultCount > 0)   {  // make sure we have data to display 

echo<<<TABLETOP 
<table border="0" cellspacing="0" cellpadding="10" align="center"> 
<tr> 
<th>id</th> 
    <th>Name</th> 
    <th>address1</th> 
    <th>address2</th> 
    <th>zip</th> 
    <th>primary phone</th> 
    <th>Seconday phone</th> 
    <th>notes</th> 
   </tr> 
TABLETOP; 
while ($row = mysql_fetch_assoc($result)) {  // Display the data from mysql 
echo<<<TABLEDATA 
  <tr> 
    <td>{$row['id']}</td> 
    <td>{$row['Name']</td> 
    <td>{$row['address1']</td> 
    <td>{$row['addres2']</td> 
    <td>{$row['zip']</td> 
    <td>{$row['primary_phone']</td> 
    <td>{$row['2ndary_phone']</td> 
    <td>{$row['notes']</td> 
  </tr> 
TABLEDATA; 

}  //  End while 

echo "</table>"; 

}  // End if 


?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm still seeing missing semicolons and braces.
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

Code: Select all

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
//db connect and select 
$db_name="bruceg_friends-family"; 
$table_name ="address_book"; 
$connection = @mysql_connect("208.65.62.13", "bruceg_webmaster", "phoenix") or die (mysql_error()); 
$db = @mysql_select_db($db_name, $connection) or die (mysql_error()); 

$result=mysql_query ("select * from address_book"); 
$resultCount = mysql_num_rows($result); 

if ($resultCount > 0)   {  // make sure we have data to display 

echo<<<TABLETOP 
<table border="0" cellspacing="0" cellpadding="10" align="center"> 
<tr> 
<th>id</th> 
    <th>Name</th> 
    <th>address1</th> 
    <th>address2</th> 
    <th>zip</th> 
    <th>primary phone</th> 
    <th>Seconday phone</th> 
    <th>notes</th> 
   </tr> 
TABLETOP; 

while ($row = mysql_fetch_assoc($result)) {  // Display the data from mysql 
echo<<<TABLEDATA 
  <tr> 
    <td>{$row['id']}</td> 
    <td>{$row['Name']}</td> 
    <td>{$row['address1']}</td> 
    <td>{$row['addres2']}</td> 
    <td>{$row['zip']}</td> 
    <td>{$row['primary_phone']}</td> 
    <td>{$row['2ndary_phone']}</td> 
    <td>{$row['notes']}</td> 
  </tr> 
TABLEDATA; 

}  //  End while 

echo "</table>"; 

}  // End if 


?>
Double checked myself, I don't see anything missing now.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

that worked finally :-)

thanks for all of your assistance guys
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

sorry to be difficult, but since their are 8 different fields to be displayed, I am needing to break them up some so that four records would display on top and four records on the bottom.

the html code would need to look like

Code: Select all

<table>
<tr>
<th></th><th></th><th></th><th></th>
</tr>
<tr>
</td><td></td><td></td></td><td></td>
</tr>
<tr>
<th></th><th></th><th></th><th></th>
</tr>
<tr>
</td><td></td><td></td></td><td></td>
</tr>
</table>


I am not sure the best way to do that given the code I am using previously given in this thread.

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have a read through the first two links in Useful Posts.
Post Reply