2012-03-06 78 views

回答

0
$query = "SELECT COUNT(column_name) AS count FROM my_table"; 
$sql = mysql_query($query); 
$result = mysql_fetch_assoc($sql); 
echo "<p>" . $result['count'] . "</p>"; 

應該做的工作

注:我用AS count才能訪問它更容易關聯數組中

0

簡單地

<? 
//Connect to the database 
$sql = "SELECT COUNT(column_name) as total FROM my_table"; 
$result = mysql_query($sql); 
$row = mysql_fetch_array($sql); 
echo $row['total']; 
?> 
0
$sql = mysql_query("SELECT COUNT(column_name) AS count FROM my_table"); 
$result = mysql_fetch_assoc($sql); 
echo '<p>'. $result['count'] .'</p>';