Simple MySQL query results incorrecy
Posted: Mon Nov 29, 2004 10:26 am
I'm running a simple query that I've done a million times, but the results are wrong and I can't figure out why.
For some reason, even though cat1 or cat2 = $searchcat, a few of the records won't show up. It seems random, but there may be something wrong in the code following the query that puts the records into columns.
Any help will be greatly appreciated!
For some reason, even though cat1 or cat2 = $searchcat, a few of the records won't show up. It seems random, but there may be something wrong in the code following the query that puts the records into columns.
Any help will be greatly appreciated!
Code: Select all
<?php
query = "SELECT * FROM portfolio WHERE cat1='$searchcat' OR cat2='$searchcat' ORDER BY name";
$r = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($r);
echo "<p><a href="portfolio.php">Search More Categories</a></p>";
$tmp_cnt = 0; // temporary variable
$per_row = 2;
for ($j = 0; $j < mysql_num_rows($r); $j++) {
if ($tmp_cnt % $per_row == 0)
echo ('<tr>');
$rowarray = mysql_fetch_array($r);
$field_num = mysql_num_fields($r);
echo ("<td>");
echo ("<table valign="top" align="center" border="0" align="center" cellpadding="1" cellspacing="2">");
if (!empty($rowarray[0])) {
echo("<tr><td valign="top" align="center" width="170"><a href="http://{$rowarray[3]}" target="_blank"><img src="images/{$rowarray[5]}" border="0"></a></td></tr>");
echo ("<tr><td valign="top" align="center"class="captiontext">") . $rowarray[0] . ("</td></tr>");
}
else {
echo("<tr> <td> </td></tr>");
}
echo ("</table>");
echo ("</td>");
$tmp_cnt = $tmp_cnt + 1;
if ($tmp_cnt % $per_row == 0)
echo ('</tr>');
}
?>