[英]SELECT COUNT if statement
Ok, so it seems like my SELECT count query doesn't work here: 好的,看来我的SELECT计数查询在这里不起作用:
<?php
$servername = " ";
$username = " ";
$password = " ";
$dbname = " ";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST['submitted1'])) {
$result= mysqli_query("SELECT COUNT (Motspillerid)
FROM SESSION
WHERE Motspillerid= 3 ");
echo $result ;
} else {
echo "Wrong" ;
}
?>
And when I press submitt nothing happens, I don't get any error message and I don't get the result. 当我按提交时,什么也没有发生,我没有收到任何错误消息,也没有得到结果。 So it's something wrong with the SELECT query I guess. 所以我猜SELECT查询有问题。
I'm noob I know, I'm new to this. 我是菜鸟,我知道,我是新来的。
:) :)
You're not calling mysqli_query()
correctly, the first argument has to be the database connection object returned by mysqli_connect
. 您没有正确调用mysqli_query()
,第一个参数必须是mysqli_connect
返回的数据库连接对象。
And after performing the query, you have to fetch the results using one of the mysqli_fetch_X()
functions. 在执行查询后,您必须使用mysqli_fetch_X()
函数之一获取结果。
if (isset($_POST['submitted1'])) {
$result= mysqli_query($conn, "SELECT COUNT(*) AS count
FROM SESSION
WHERE Motspillerid= 3 ");
$row = mysqli_fetch_assoc($result);
echo $row['count'];
} else {
echo "Wrong" ;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.