目前我正在开发一个移动图书馆应用程序,它需要借书。我希望能够检查与可用总数相比有多少本书被 checkout 。我正在努力将 mysqli_query
结果转换为一个整数,以便与可用图书总数进行比较。如果这是一个简单的答案,我深表歉意(我是新手),因为我进行了相当多的挖掘,但找不到适合我的场景的答案。
<?php
require "conn.php";
$userID = "2";
$book_id = "1";
$mysql_qry = "select COUNT(*) from books_checked_out where bookID=$book_id";
$result = mysqli_query($conn, $mysql_qry);
//Somewhere here convert the $result into $quantity, which would be an int
if($quantity >= 2) {
echo "more books checked out than in stock";
}
else if($quantity < 2) {
echo "less books checked out than in stock";
}
?>
感谢任何帮助,谢谢!
最佳答案
这会起作用
$result = $result->fetch_array();
$quantity = intval($result[0]);
关于php - 如何将 mysqli_query 结果转换为 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48698663/