作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
connect_error); -6ren">
<?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 连接的 Like 按钮,一切正常,但问题出在 Else 语句
else
include ("likee.php");
它不起作用,而 if 语句起作用。逻辑 is Likee.php 包含 Likee.php 包含的脚本,反之亦然,并且每当它们是已放置的“喜欢”时,就会显示“喜欢”按钮,但每当它们不是“喜欢”时,“喜欢”按钮是不可见的
最佳答案
你说“只要没有喜欢,喜欢按钮就看不见”。这是因为当没有“喜欢”时,您永远不会执行包含“喜欢”或“不喜欢”按钮的代码部分
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");
}
关于php - If 语句有效,而 Else 语句无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37760769/
我是一名优秀的程序员,十分优秀!