View Full Version : display empty count result
mulaus
11-29-2014, 07:09 AM
Hi
i have this code..how do i display empty count result ?
<?php
// Make a MySQL Connection
$query = "SELECT type, COUNT(name) FROM products GROUP BY type";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(name)'] ." ". $row['type'] ." items.";
echo "<br />";
}
?>
jan127
12-08-2014, 07:45 PM
<?php
// Make a MySQL Connection
$query = "SELECT type, COUNT(name) as count FROM products GROUP BY type";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['count'] ." ". $row['type'] ." items.";
echo "<br />";
}
luattrihung11
12-16-2014, 09:08 AM
<?php
// Make a MySQL Connection
$query = "SELECT type, COUNT(name) as count FROM products GROUP BY type";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['count'] ." ". $row['type'] ." items.";
echo "<br />";
}
it's ok, thanks jan127
deemtech
12-16-2014, 09:46 AM
Using this code you can display empty count result:
$total_rows = mysql_num_rows($result);
if($total_rows>0){
// please use your code in this section
}
<?php
// Make a MySQL Connection
$query = "SELECT type, COUNT(name) FROM products GROUP BY type";
$result = mysql_query($query) or die(mysql_error());
$total_rows = mysql_num_rows($result);
if($total_rows>0){
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(name)'] ." ". $row['type'] ." items.";
echo "<br />";
}
}
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.