Simple Count Records from MySQL DB Table
<?
$sql = "SELECT COUNT(*) AS count FROM table WHERE this = '$this'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$count = $row["count"];
}
echo $count;
?>



me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Hackdemian
impomatic
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
You can do just:
$row = mysql_fetch_array($result);
$count = $row['count'];
You should always check to make sure that $result is populated before reading a value from it.
$result = mysql_query($sql);
if($result)
{
$row = mysql_fetch_row($result);
$count = $row[0];
echo $count;
}
else
{
echo "no result from database.";
}
and
u must use a field name in COUNT() function for performance. like:
SELECT COUNT(this) FROM my_table WHERE this='$this'
http://www.morad.info/
$sql = "SELECT * FROM table";
$result = mysql_query($sql, $connection);
if ($result)
print mysql_num_rows($result);
else
print "There was no result returned";