Hey all,
I'm hoping someone can help me out. I'm coding a news snippet displayer that pulls it's data from a MYSQL database. The query code and display code are below. I keep getting an error from MYSQL that reads:
Warning: 2 is not a valid MySQL result resource in /public_html/index.php on line 135
Line 135 is the while statement:
while ($row = mysql_fetch_array($result))
I'm hoping someone sees something I don't. I'm by no means an expert, but damned if I see what's wrong. Please help!
it should be mentioned that I can only get one iteration of the script to work. It stops looping after the first time.
Ras.
// some variables such as $a, $b, and $ci are defined in the func.inc included at start of html
<?php
// number of items in highlights section
$num_items = 3;
// query for highlights
// default connection function defined in func.inc at start of document
connect();
$query = "SELECT a.storyID, a.issueID, a.cat, a.headline, a.teaser, a.article_URL, p.url, p.storyID FROM $a as a LEFT JOIN $p as p
ON a.storyID = p.storyID
WHERE a.cat LIKE 'HL%'
AND a.issueID = $ci
LIMIT 0, $num_items";
$result = mysql_query($query);
// reports errors. function defined in func.inc
error_report($result);
// display contents
while ($row = mysql_fetch_array($result)) // this is line 135 that is supposed to have an error
{
?>
<table width="180" border="0" cellspacing="0" cellpadding="0" bgcolor="#cc6600" height="168">
<tr>
<td align="center" valign="middle">
<table width="178" border="0" cellspacing="0" cellpadding="0" height="166">
<tr height="24">
<td bgcolor="white" width="10" height="24"><img src=images/spacer.gif width=10 height=10 alt=></td>
<td align="left" bgcolor="white" height="24" valign="center"><b>
<h3>:: <?php echo $row['headline'];?></h3>
</b></td>
<td bgcolor="white" width="10" height="24"><img src=../images/spacer.gif width=10 height=10 alt=></td>
</tr>
<tr height="1">
<td colspan="3" bgcolor="#ff9966" height="1"></td>
</tr>
<tr height="10">
<td colspan="3" bgcolor="#fff3e7" height="10"><img src=../images/spacer.gif width=10 height=10 alt=></td>
</tr>
<tr height="131">
<td bgcolor="#fff3e7" width="10" height="131"><img src=../images/spacer.gif width=10 height=10 alt=></td>
<td valign="top" bgcolor="#fff3e7" height="131">
<?php
if (!empty($row['url']))
{
if ($row['storyID'] == $row[7])
{echo "<img src='http://www.mydomain.com/images/'".$row['url']."' height='32' width='32' align='left' border='0'>";}
}
echo $row['teaser'];
echo "<p></p>";
if (!empty($row['article_URL']))
{
echo "<font color=cc6600>:: </font><a href='http://".$row['article_URL']."' target='_blank'>Read more...</a>";
}
?>
</td>
<td bgcolor="#fff3e7" width="10" height="131"><img src=../images/spacer.gif width=10 height=10 alt=></td>
</tr>
</table>
</td>
</tr>
</table>
<?php mysql_free_result($result); }
// end of display contents
?>
<p></p>