这是我的问题:
$qry1 = "SELECT COUNT('name') FROM `brands` WHERE `catagory_id` = '".$id."';";
$res = mysqli_query($conn, $qry1);
我想要 count的值,并希望在另一个查询中使用它。怎么可能?
答案 0 :(得分:1)
两个步骤:
1.为count(name)
,total
计算的值提供有意义的名称,例如
2.使用名称total
$qry1 = "SELECT COUNT(name) as total FROM `brands` WHERE `catagory_id` = '".$id."';";
$count = $mysqli->query($conn, $qry1)->fetch_object()->total;
答案 1 :(得分:0)
尝试;
$qry1 = "SELECT COUNT(name) as counts FROM brands WHERE catagory_id = '".$id."';";
$res = mysqli_query($conn, $qry1);
$row = mysqli_fetch_array($res);
$count = $row["counts"];
现在这个$ count变量保存了该值。您可以在其他查询中包含此变量。