I want to echo only the first 10 rows, but I need to count the total number of rows affected by the query.
I was doing a LIMIT 10 and then counting with
You have to make 2 queries: the first one will count all rows, the second one will return 10 rows:
$count = 0;
$query = "SELECT count(*) as count FROM Badges WHERE UID = '$user'";
$rs = mysql_query($query);
if (mysql_errno() == 0)
{
$r = mysql_fetch_object($rs);
$count = $r->count;
}
if ($count > 0)
{
$query = "SELECT * FROM Badges WHERE UID = '$user' ORDER by Date DESC LIMIT 10";
$rs = mysql_query($query);
if (mysql_errno() == 0)
{
while ($r = mysql_fetch_array($rs))
{
echo $r['Site'];
}
}
}