count the numbers. count the numbers...
Posted: Fri Oct 27, 2006 10:48 am
Hey guys, happy Friday!
Having a wee problem with counting some mysql_num_rows() at the moment.
well, I'm not really. I'm getting all the numbers I need but it's more a problem of displaying it in the right place.
Check tha code:
see I want to display the search results where it's trying to output them, but because $num doesn't get populated until after the while loops have finished, it returns zero everytime.
help!
thanks in advance you nice people
Having a wee problem with counting some mysql_num_rows() at the moment.
well, I'm not really. I'm getting all the numbers I need but it's more a problem of displaying it in the right place.
Check tha code:
Code: Select all
$tbSQL = "SHOW TABLES";
$tbQuery = mysql_query($tbSQL);
$tNum = 0;
$num = 0;
if ($num >= 2 || $num == 0)
{
echo "There are " . $num . " results for your search.<br/><br/>";
}
elseif ($num == 1)
{
echo "There is " . $num . " result for your search.<br/><br/>";
}
while ($tb = mysql_fetch_array($tbQuery))
{
$sql[$tNum] = "SELECT * FROM " . $tb[0] . " WHERE title LIKE '%" . $search . "%' OR sub_section LIKE '%" . $search . "%' OR summary LIKE '%" . $search . "%' OR article LIKE '%" . $search . "%' ORDER BY title ASC";
$query[$tNum] = mysql_query($sql[$tNum]);
$num += (int)mysql_num_rows($query[$tNum]);
echo "<table>";
echo "<tr><td style=\"font-weight:bold;font-size:16px\">Results from " . ucwords(str_replace("_"," ", $tb[0])) . "</td></tr>";
echo "<tr><td>";
while($row[$tNum] = mysql_fetch_array($query[$tNum]))
{
echo "<table style=\"padding:20px;border-bottom:solid 1px #FF0F21\">";
echo "<tr><td style=\"color:#FF0F21;font-weight:bold;text-decoration:none\">" . str_replace($search,"<span style=\"background-color:#999999\">". $search . "</span>", $row[$tNum]['sub_section']) . "</td></tr>";
echo "<tr><td style=\"color:#999999;text-decoration:none;padding-left:30px\"><a href=\"test.php?s=" . $tb[0] . "&sub=" . $row[$tNum]['sub_section'] . "&ID=" . $row[$tNum]['ID'] . "\">" . str_replace($search,"<span style=\"background-color:#90EE90\">". $search . "</span>", $row[$tNum]['title']) . "</a></td></tr>";
echo "<tr><td><strong>" . str_replace($search,"<span style=\"background-color:#90EE90\">". $search . "</span>", $row[$tNum]['summary']) . "</strong></td></tr>";
echo "<tr><td>" . str_replace($search,"<span style=\"background-color:#90EE90\">". $search . "</span>", $row[$tNum]['article']) . "</td></tr>";
echo "</table>";
}
echo "</td></tr>";
echo "</table>";
$tNum ++;
}help!
thanks in advance you nice people