我是 PHP 的新手,正在努力解决一些问题。
该表有“链接”和“评级”列,我从表中随机选择一行。
$select = mysqli_select_db($conn, "database");
$result2 = mysqli_query($conn, "SELECT * FROM photos ORDER BY rand() LIMIT 1");
?>
如果我添加
while ($row = $result2->fetch_assoc()) { echo $row['rating']; };
hiện hữu$result2
的正下方, 它被正确回显。但这不是我想要的。我后面有一大堆 HTML 代码,还有更多的 php 标签。
它需要放在标题中
标记是上面编写的代码下方的许多行。
fetch_assoc()) { echo $row['rating']; }; ?>
h1
中没有任何回显标签。
您还有其他 SQL 查询 - 您忘记提及了。
将SQL查询的结果保存到变量中,然后只写这个变量。
$result2 = ...; // SQL query
$row = $result2->fetch_assoc(); // no while loop necessary if you hav ejust one records from database
$rating = $row['rating'];
...
?>
...
Tôi là một lập trình viên xuất sắc, rất giỏi!