gpt4 book ai didi

php - sql查询不返回第一行

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:51 25 4
gpt4 key购买 nike

<分区>

每当我使用:while($x = mysqli_fetch_array($y)) 然后是 echo $x,它会返回除第一行以外的所有内容。

表格:

论坛用户

  • users.user_id
  • users.username
  • users.password
  • users.image

forum.forums

  • forums.forum_id
  • forums.user_id
  • forums.name

这是我的代码:

<?php
session_start();
$con = new mysqli("localhost", "root", "", "forum");
if(!isset($_SESSION["online"])==1) {
$_SESSION["offline"] = "true";
}
$username = $_SESSION["online"];
$u_query = "SELECT * FROM forum.users WHERE users.username = '".$username."'";
$u_result = $con -> query($u_query);
$u_row = mysqli_fetch_array($u_result);
if(isset($_POST["logout"])) {
session_unset();
session_destroy();
header("Location: login.php");
}
$f_search = "SELECT * FROM forum.forums WHERE user_id = '".$u_row['user_id']."'";
$f_result = $con -> query($f_search);
$f_row = mysqli_fetch_array($f_result);
?>
<html>
<head>
<title>Home</title>
<charset = "UTF-8">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>

<div id="header">
<div id="user">
<img src="<?php echo $u_row['image']; ?>" id="user-image">
<?php echo $u_row["username"]; ?>
<form method="post">
<input type="submit" name="logout" value="sign out">
</form>
</div>
</div>

<?php if(mysqli_num_rows($f_result)>= 0) { ?>
<div>
<div>Your forums:</div><table><tr>
<?php while($f_row = mysqli_fetch_array($f_result)) { ?>
<td><a href="forum.php?forumid=<?php echo $f_row['forum_id']; ?>"><?php echo $f_row["name"]; ?></a></td>
<td></td>
<?php } ?>
</tr></table>
</div>
<?php } ?>
</body>
</html>

为什么不返回第一行?

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