你好,所以我试图得到mysql数据库中一列的总和是它的0 preform查询1 else查询2
问题是,即使来自mysql phpmyadmin的值显示1或2,好像在if条件中存在问题,它总是进入第一个条件而不是其他条件
<?php
$servername = "localhost:3306";
$username = "****";
$password = "*****";
$dbname = "****";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$search = $_GET['search'];
$sqlx = "SELECT SUM(`verified`) AS value_sum FROM Numbers WHERE `number` = ".$search." ";
$resultx = $conn->query($sqlx);
$sum = $row['value_sum'];
if ($sum == 0)
{
$sql = "SELECT * FROM `Numbers` WHERE (`number` LIKE '%".$search."%' or `name` LIKE '%".$search."%') and `blocked` = 0 and `verified` = 0 GROUP BY `name` Limit 20";
$result = $conn->query($sql);
}
else
{
$sql = "SELECT * FROM `Numbers` WHERE (`number` LIKE '%".$search."%' or `name` LIKE '%".$search."%') and `blocked` = 0 and `verified` = 1 GROUP BY `name` Limit 1";
$result = $conn->query($sql);
}
答案 0 :(得分:3)