displaying information in MyQL into an HTML table
Moderator: General Moderators
-
bruceg
- Forum Contributor
- Posts: 174
- Joined: Wed Mar 16, 2005 11:07 am
- Location: Morrisville, NC
- Contact:
I took out a brace that looked like it didn't belong, but that didn't fix the problem.
I now have:
if someone has a php debugging program, they could test this on, I would greatly appreciate it.
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
?>-
blackbeard
- Forum Contributor
- Posts: 123
- Joined: Thu Aug 03, 2006 6:20 pm
I forgot the second half of the curly braces for the $row data inside the while loop. Try it now.bruceg wrote:I took out a brace that looked like it didn't belong, but that didn't fix the problem.
I now have:
if someone has a php debugging program, they could test this on, I would greatly appreciate it.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 ?>
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:
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
?>-
blackbeard
- Forum Contributor
- Posts: 123
- Joined: Thu Aug 03, 2006 6:20 pm
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
?>-
bruceg
- Forum Contributor
- Posts: 174
- Joined: Wed Mar 16, 2005 11:07 am
- Location: Morrisville, NC
- Contact:
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
I am not sure the best way to do that given the code I am using previously given in this thread.
thanks
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