I've been having some really weird problems with a very simple PHP
app. I'm wondering if anyone can help me sort this out.
I have a page that prints out the results of a MySQL query as an HTML
table using a for loop: nothing too exotic there.
However, sometimes one column shows the data it's supposed to contain,
and sometimes it doesn't. (The name of the field is "category".) I
checked the actual DB data. The data is there.
That's not all. I just visited the page and got the result below. PHP
has inserted "(" characters between the table rows. I can see how
maybe a syntax error could cause that, but why would it only happen
sometimes?
Why does that column of data disappear and then reappear when I visit
the page later?
Php code and HTML output are given below.
Setup information:
FreeBSD 4.7
PHP 4.3.8
Zend Optimizer 2.5.1
MySQL 4.0.18
--------------------------------------------------------------------------
PHP CODE
--------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>AFWH Website Admin</title>
<? include("../include/headerItems.htm"); ?>
</head>
<body>
<?
$con = mysql_connect("localhost", "MYUSERNAME", "MYPASSWORD");
if (!$con)
{
echo "Error connecting to DB";
}
mysql_select_db("articles");
$statement = "SELECT * FROM articles";
$result = mysql_query($statement);
?>
<h1 id="pageTitle"><? echo mysql_num_rows($result); ?>
articles</h1>
<p id="menu"><a href="articleFormIn.php">Add article</a> | <a
href="listArticles.php">List all</a></p>
<table id="articleListing">
<tr>
<td>Filename</td>
<td>Category</td>
<td>Title</td>
<td>Date</td>
<td>Publish</td>
<td> </td>
<td>Idx. pg. code</td>
</tr>
<?
$rowClass = "white";
for ($i = 0 ; $i < mysql_num_rows($result) ; $i++)
{
if ($rowClass == "white")
{
$rowClass = "grey";
} else {
$rowClass = "white";
}
$row = mysql_fetch_array($result);
?>
<tr class="<? echo $rowClass; ?>">
<td><? echo $row["filename"]; ?>
</td>
<td><? echo $row["category"]; ?>
</td>
<td><a href='editArticle.php?id=<? echo $row["ID"]; ?>'>
<? echo $row["title"]; ?>: <? echo $row["subtitle"]; ?>
</a></td>
<td><? echo $row["date"]; ?>
</td>
<td>
Publish >
<a href="publish.php?id=<? echo $row["ID"] ?>&curr=1">Current</a>
|
<a href="publish.php?id=<? echo $row["ID"] ?>&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=<? echo $row["ID"] ?>">DEL from
DB</a>
</td>
<td><a href='indexPgCode.php?id=<? echo $row["ID"]; ?>'>Snippet</a>
</td>
</tr><?
}
?>
</table>
</body>
</html>
--------------------------------------------------------------------------
RESULTING HTML OUTPUT
--------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>AFWH Website Admin</title>
<meta http-equiv="Content-type"
content="text/html; charset=us-ascii" />
<meta http-equiv="Content-Language"
content="en-us" />
<meta name="ROBOTS"
content="NONE" />
<style type="text/css">
/*<![CDATA[*/
@import url(/admin/css/admin.css);
/*]]>*/
</style> </head>
<body>
<h1 id="pageTitle">12 articles</h1>
<p id="menu"><a href="articleFormIn.php">Add article</a> | <a
href="listArticles.php">List all</a></p>
<table id="articleListing">
<tr>
<td>Filename</td>
<td>Category</td>
<td>Title</td>
<td>Date</td>
<td>Publish</td>
<td> </td>
<td>Idx. pg. code</td>
</tr>
( <tr class="grey">
<td>/articles/free/newmodelofarousal.htm </td>
<td> </td>
<td><a href='editArticle.php?id=8'>
A New Model of Arousal: At mid-life, desire may need a
jump start </a></td>
<td>April, 2004 </td>
<td>
Publish >
<a href="publish.php?id=8&curr=1">Current</a> |
<a href="publish.php?id=8&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=8">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=8'>Snippet</a>
</td>
</tr>
( <tr class="white">
<td>/articles/free/combattingdepression.htm
</td>
<td> </td>
<td><a href='editArticle.php?id=9'>
Combatting Depression with a Better Diet: What omega-3
fatty acids can do for you </a></td>
<td>April, 2004 </td>
<td>
Publish >
<a href="publish.php?id=9&curr=1">Current</a> |
<a href="publish.php?id=9&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=9">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=9'>Snippet</a>
</td>
</tr>
( <tr class="grey">
<td>/articles/paid/october_04/troublesleeping.htm
</td>
<td>SLEEP </td>
<td><a href='editArticle.php?id=27'>
More Trouble Sleeping than Your Spouse?: Anxiety or
Depression May Be the Problem </a></td>
<td>October, 2004 </td>
<td>
Publish >
<a href="publish.php?id=27&curr=1">Current</a> |
<a href="publish.php?id=27&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=27">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=27'>Snippet</a>
</td>
</tr>
( <tr class="white">
<td>/articles/paid/october_04/beyondcholesterol.htm
</td>
<td>SELFCARE </td>
<td><a href='editArticle.php?id=28'>
Predicting Heart Disease: Beyond Cholesterol
</a></td>
<td>October, 2004 </td>
<td>
Publish >
<a href="publish.php?id=28&curr=1">Current</a> |
<a href="publish.php?id=28&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=28">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=28'>Snippet</a>
</td>
</tr>
( <tr class="grey">
<td>/articles/free/controversyoverkegels.htm
</td>
<td> </td>
<td><a href='editArticle.php?id=11'>
The Controversy over Kegels: Are women doing them
correctly? </a></td>
<td>June, 2004 </td>
<td>
Publish >
<a href="publish.php?id=11&curr=1">Current</a> |
<a href="publish.php?id=11&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=11">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=11'>Snippet</a>
</td>
</tr>
( <tr class="white">
<td>/articles/free/recurringnightmares.htm
</td>
<td> </td>
<td><a href='editArticle.php?id=12'>
Recurring Nightmares and Post-traumatic Stress: Twice as
many women suffer as men </a></td>
<td>April, 2004 </td>
<td>
Publish >
<a href="publish.php?id=12&curr=1">Current</a> |
<a href="publish.php?id=12&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=12">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=12'>Snippet</a>
</td>
</tr>
( <tr class="grey">
<td>/articles/paid/october_04/testosterone.htm
</td>
<td>INTERVIEW </td>
<td><a href='editArticle.php?id=29'>
Is Testosterone the Answer to Low Libido?: Researcher
Susan Davis tells when and how it works </a></td>
<td> </td>
<td>
Publish >
<a href="publish.php?id=29&curr=1">Current</a> |
<a href="publish.php?id=29&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=29">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=29'>Snippet</a>
</td>
</tr>
( <tr class="white">
<td>/articles/free/sexafterprostate.htm </td>
<td> </td>
<td><a href='editArticle.php?id=14'>
Sex after Prostate Surgery: What every couple needs to
know </a></td>
<td>April, 2004 </td>
<td>
Publish >
<a href="publish.php?id=14&curr=1">Current</a> |
<a href="publish.php?id=14&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=14">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=14'>Snippet</a>
</td>
</tr>
( <tr class="grey">
<td>/articles/free/copingwithpms.htm </td>
<td> </td>
<td><a href='editArticle.php?id=15'>
Coping with PMS: Can low-dose antidepressants help?
</a></td>
<td>April, 2004 </td>
<td>
Publish >
<a href="publish.php?id=15&curr=1">Current</a> |
<a href="publish.php?id=15&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=15">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=15'>Snippet</a>
</td>
</tr>
( <tr class="white">
<td>/articles/free/destress.htm </td>
<td> </td>
<td><a href='editArticle.php?id=17'>
How to De-Stress: A Brief Guide to Relaxation Tools
</a></td>
<td>June, 2004 </td>
<td>
Publish >
<a href="publish.php?id=17&curr=1">Current</a> |
<a href="publish.php?id=17&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=17">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=17'>Snippet</a>
</td>
</tr>
( <tr class="grey">
<td>/articles/free/erectiledysfunction.htm
</td>
<td>ABOUT MEN </td>
<td><a href='editArticle.php?id=19'>
Straight Talk About Erectile Dysfunction: When the Body
Won\'t Respond </a></td>
<td>February, 2004 </td>
<td>
Publish >
<a href="publish.php?id=19&curr=1">Current</a> |
<a href="publish.php?id=19&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=19">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=19'>Snippet</a>
</td>
</tr>
( <tr class="white">
<td>/articles/free/fightingfatigue.htm </td>
<td> </td>
<td><a href='editArticle.php?id=21'>
Fighting Fatigue: How to get a more satisfying sleep
</a></td>
<td>February, 2004 </td>
<td>
Publish >
<a href="publish.php?id=21&curr=1">Current</a> |
<a href="publish.php?id=21&curr=0">Archive</a>
</td>
<td>
<a href="deleteConfirm.php?id=21">DEL from DB</a>
</td>
<td><a href='indexPgCode.php?id=21'>Snippet</a>
</td>
</tr> </table>
</body>
</html>