Page 1 of 2
displaying information in MyQL into an HTML table
Posted: Sat Aug 05, 2006 9:55 am
by bruceg
I am trying to display records I have entered into a MYSQL table into a webpage with an HTML table and I am just getting a blank page as out put.
here is what I have:
Code: Select all
<table border="0" CELLSPACING="0" CELLPADDING="10" align="center">
<?php
//db connect and select
$db_name="myDBname";
$table_name ="mytablename";
$connection = @mysql_connect("datbaseconnection", "username", "password")
or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
}
$result=mysql_query ("select * from mytablename");
$count = 1;
$column = 1;
//loop statement
while ($myrow = mysql_fetch_array ($result))
{
// first column display
if ($column == 1)
{
//field is the column in your table
printf("<tr><td>%s</td>",$myrow["field"]);
}
else{
//second column display
printf("<td>%s</td></tr>",$myrow["field"]);
}
$count += 1;
$column = $count % 2;
}
?>
</table>
the fields I want dispayed are id, Name,address1, address2, zip, primary_phone, 2ndary_phone,notes
plasease assist with what I would need to ammend to get this to work. I realize that I may be way off base with what I am attempting so far!!
Posted: Sat Aug 05, 2006 2:16 pm
by blackbeard
This is what I do when displaying data from mysql into a html table:
Code: Select all
/db connect and select
$db_name="myDBname";
$table_name ="mytablename";
$connection = @mysql_connect("datbaseconnection", "username", "password")
or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
}
$result=mysql_query ("select * from mytablename");
$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['adsress1']</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
Hope this is what you're looking for.
Posted: Sat Aug 05, 2006 3:00 pm
by Ollie Saunders
bruceg, please ammend the topic subject by editing your first post. MSQL is different from MySQL and this may put people off reading your post.
Your problem:
Are you getting no output at all? Have you tried view source?
It may help to add this to the top of your code:
Posted: Sun Aug 06, 2006 3:32 pm
by bruceg
o.k, I have edited the subject line to reflect MySQL which is the database I am using.
I am using the code suggested by blackbeard and still get a blank white page.
the URL is here
http://www.inspired-evolution.com/display_addresses.php
I added this as well,
but only get the blank white page. I usually at least get an error!
Posted: Sun Aug 06, 2006 3:44 pm
by Ollie Saunders
ok add this too, above error_reporting, sorry i meant to say this earlier
Posted: Sun Aug 06, 2006 4:04 pm
by feyd
Run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");
$gle = get_loaded_extensions();
$rows = array();
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . "\n";
}
if ($cli)
{
$le = $eol . $le;
}
else
{
$le = '<pre>' . $le . '</pre>';
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
$er = $er . ' (' . implode(' | ', $e) . ')';
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body>' . "\n";
}
echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;
if (!$cli)
{
echo '</body></html>' . "\n";
}
?>
Posted: Sun Aug 06, 2006 8:11 pm
by bruceg
Hey Feyd,
the results can be found here:
http://www.inspired-evolution.com/test.php
I don't have access to the PHP INI stuff, since I am working with a remote hosting company
Posted: Sun Aug 06, 2006 8:47 pm
by RobertGonzalez
Blank pages are almost always a syntax error in the script when display_errors is Off. If you cannot modify your php.ini, you are going to have to go through your code line by line looking for (the usual suspects) unmatched braces/parentheses or missing semicolons.
Posted: Sun Aug 06, 2006 8:54 pm
by Ollie Saunders
ole wrote:ok add this too, above error_reporting, sorry i meant to say this earlier
Hello?
Posted: Sun Aug 06, 2006 9:15 pm
by feyd
.htaccess files can change the display_errors setting too.
Posted: Sun Aug 06, 2006 9:15 pm
by RobertGonzalez
ole wrote:ole wrote:ok add this too, above error_reporting, sorry i meant to say this earlier
Hello?
Was this for me?
bruceg wrote:... I don't have access to the PHP INI stuff, since I am working with a remote hosting company
ini_set(), as per
the manual...
Note: Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.
A fatal error will be thrown for syntax related issues like the unmatched braces and missing semicolons. Because of that, even changing the 'display_errors' directive with
ini_set() will not show information on those types of issues. Unless you change it in php.ini, you will still get a blank page.
Posted: Sun Aug 06, 2006 9:34 pm
by bruceg
ole wrote:ole wrote:ok add this too, above error_reporting, sorry i meant to say this earlier
Hello?
I added that and still get the blank page. I will look at it tomorrow in a better PHP editor.
Posted: Sun Aug 06, 2006 9:46 pm
by Ollie Saunders
I added that and still get the blank page. I will look at it tomorrow in a better PHP editor.
Ah ok.
A fatal error will be thrown for syntax related issues like the unmatched braces and missing semicolons. Because of that, even changing the 'display_errors' directive with ini_set() will not show information on those types of issues. Unless you change it in php.ini, you will still get a blank page.
Now that I did not know.
Was this for me?
For everybody but its sorted now

Posted: Sun Aug 06, 2006 9:55 pm
by RobertGonzalez
Cool.
Posted: Mon Aug 07, 2006 9:09 am
by bruceg
I brought the code into DW and uploaded and I still get the blank page. I cannot see where there is ana error in the following code. Can anyone else?
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", "username", "password")
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
?>