我需要显示总共的标题字符。 $ totals只返回0,我哪里错了?
有什么建议吗?
$characters_qty = mysql_query("
SELECT LENGTH(title) AS title_quantity, title FROM orders
");
$res_characters_qty = mysql_fetch_assoc($characters_qty);
$totals = $res_characters_qty ['title_quantity'];
echo $totals;
答案 0 :(得分:0)
请尝试使用至少使用mysqli
的内容。测试了它和它的工作。
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_db_name";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT LENGTH(title) AS title_quantity, title FROM orders";
$res_characters_qty = mysqli_query($conn, $sql);
if (mysqli_num_rows($res_characters_qty ) > 0) {
while($row = mysqli_fetch_assoc($res_characters_qty )) {
echo $row['title_quantity']. '<br/>';
}
}
$conn->close();