[英]Print output in php using Sql queries
I am working on PHP where i want to fetch the count of a particular column 'uid' from users table. 我在PHP上工作,我想从用户表中获取特定列“ uid”的计数。 The output window is not displaying anything.
输出窗口未显示任何内容。 following is the code.
以下是代码。 Can anybody, help me in rectifying this code.
谁能帮我纠正此代码。
<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("rth_db");
$data = mysql_query("SELECT COUNT(uid) AS Total FROM users", $link);
$number = mysql_fetch_array($data);
echo $number;
echo 'Connected successfully';
mysql_close($link);
?>
you should address your data differently 您应该以不同的方式处理数据
echo $number["Total"];
Also, mysql is deprecated, have a look at PDO. 另外,不建议使用mysql,请看一下PDO。 This also is better for security and so on.
这对于安全性等也更好。 You can check the PHP.NET page for more info on this
您可以检查PHP.NET页面以获取更多有关此的信息
change this 改变这个
echo $number;
to 至
print_r($number);
OR 要么
echo $number['Total'];
Because $number
is array
not string
. 因为
$number
是array
而不是string
。
try using this : 尝试使用这个:
<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("rth_db");
$data = mysql_query("SELECT COUNT(uid) AS Total FROM users", $link);
$number = mysql_fetch_array($data);
echo $number['total'];
echo 'Connected successfully';
mysql_close($link);
?>
i have just edited one line if u notice...hope this works :) 我刚刚编辑了一行,如果你注意到...希望这行得通:)
你也可以使用
var_dump($number);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.