connect_error); -6ren">
gpt4 book ai didi

php - If 语句有效,而 Else 语句无效

转载 作者:行者123 更新时间:2023-11-29 20:54:14 25 4
gpt4 key购买 nike

<?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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com