Hello out there,
I'm working on a site that will display some information in html tabular format, but I keep getting an SQL error when I run the script. The idea is that some of the included people have website addresses. If they do, their name should be hyperlinked to that address. If not, just their name should appear. The script is as follows:
<table width="90%" border="2" cellspacing="0" cellpadding="3">
<?php
// access database
@$db = mysql_connect("localhost", "username", "password");
// error control
if (!db)
{
echo 'Error: could not access database. Please try again later.';
exit;
}
// variables
mysql_select_db("db_name");
$query = "SELECT * FROM table";
$result = mysql_query($query);
$num_results = mysql_num_rows($query);
// formatting results
for ($i = 0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<tr>';
// check if website field exists or is empty
if ($row['website'] == 'NULL')
{
echo '<td colspan="2">';
echo $row['name'];
echo '</td>';
break;
} else {
echo '<td colspan="2"><a href=http://';
echo $row['website'];
echo '/ target="_blank">';
echo $row['name'];
echo '</a></td>';
}
echo '</tr><tr><td width="50%">Phone: ';
echo $row['phone'];
echo '</td>';
echo '<td width="50%">Fax: ';
echo $row['fax'];
echo '</td>';
echo '</tr><tr><td colspan="2">';
echo $row['description'];
echo '</td></tr>';
}
?>
</table>
Any help is greatly appreciated! I've just started coding PHP, so if you have suggestions to clean up the code (and thereby improve my future coding abilities) I would love to hear them as well.
Take care all you gurus out there.