<?php
// Check connection
$servername = "localhost";
$username = "root";
$password = "1234";
$dbname = "project";
htmlspecialchars($a = $row1['stno']);
$d1 = $row7['userID'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM likes WHERE rec = $a";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$z4 = $row['do'];
if ($d1 == $z4)
{
include ("unlikee.php");
}
else {
include ("likee.php");
}
}
}
$conn->close();
?>
这是一个与我的sql连接的按钮,一切正常,但问题是用Else语句
else
include ("likee.php");
它没有工作,而if语句工作了。逻辑是不同的.php包含脚本,不像likee.php包含反之亦然,每当它们已经放置时,不同的按钮会显示,但只要它们不相似,Like按钮就是不可见的
答案 0 :(得分:0)
你说“只要没有相似的东西,就像看不见的东西一样”。那是因为你没有执行包含类似代码的部分代码,或者在没有喜欢的情况下执行不同的按钮
if ($result->num_rows > 0) {
更新了代码段。当结果行数为0时,执行else以包含likee.php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$z4 = $row['do'];
if ($d1 == $z4) {
include ("unlikee.php");
}
} else {
include ("likee.php");
}