我有一個簡單MySQL query
:SELECT COUNT(column_name) FROM my_table
打印的MySQL查詢與PHP結果在HTML頁面中
如何print results (in html pages)
與PHP在已有的數據庫連接? 對不起,這個愚蠢的答案,我只是學習PHP :(
我有一個簡單MySQL query
:SELECT COUNT(column_name) FROM my_table
打印的MySQL查詢與PHP結果在HTML頁面中
如何print results (in html pages)
與PHP在已有的數據庫連接? 對不起,這個愚蠢的答案,我只是學習PHP :(
$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
才能訪問它更容易關聯數組中
簡單地
<?
//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'];
?>
$sql = mysql_query("SELECT COUNT(column_name) AS count FROM my_table");
$result = mysql_fetch_assoc($sql);
echo '<p>'. $result['count'] .'</p>';