gpt4 book ai didi

php - while 循环未运行 if 语句正确

转载 作者:行者123 更新时间:2023-11-30 01:21:08 25 4
gpt4 key购买 nike

所以我有一个 while 循环,它确实在数据库和 if 语句等方面工作。但是由于某种原因,if 语句没有正确运行

这是代码(已编辑)

<?php session_start( ); ?>
<?php include 'core/init.php';
include 'includes/header.php';

require 'core/database/db_connection.php';

function friend_check($user_id, $friend_id) {
$result = mysql_query("SELECT * FROM fyp_friends WHERE user_id={$user_id} AND friend_id={$friend_id} AND type=1");
$num_rows = mysql_num_rows($result);

echo $num_rows;
}

?>
<link rel="stylesheet" type="text/css" href="style/members.css">
<?php
/*------------------------------------------------------------------------------------- --------------------*/
//Get user information from fyp_users
$sql = ("SELECT user_id, user_name, first_name, last_name, email, profile FROM fyp_users");
$user =mysql_query($sql) or die(mysql_error());
//$userinfo = mysql_fetch_array($user);
//echo $userinfo['user_id'];

//Get friend information from fyp_users
//$sql = ("SELECT user_id, friend_id, type FROM fyp_friends");
//$friend =mysql_query($sql) or die(mysql_error());
//$friendinfo = mysql_fetch_array($friend);
//echo $friendinfo['user_id'];
?>

<?php
while ($usermain = mysql_fetch_array($user)) {

echo '<div id="friends">';
echo '<div class="profilepiclarge"><img src="', $usermain['profile'], '"alt="', $usermain['first_name'],'\'s Profile Image"></div>';
?>
<div class="userinfo">
<?php
echo "</br>{$usermain['first_name']}";
echo "</br>{$usermain['last_name']}";
echo "</br>{$usermain['email']}";
echo "</br>{$usermain['user_name']}</br>";
echo '<div class="viewprofile">';
echo "<a href='profile.php?user_name={$usermain['user_name']}'>View Profile</a>";
echo '</div>';

$sql = ("SELECT user_id, friend_id, type FROM fyp_friends WHERE user_id= {$usermain['user_id']}");
$friend =mysql_query($sql) or die(mysql_error());

$friend_result = friend_check($session_user_id, $usermain['user_id']);
echo $friend_result;
if ($usermain['user_id'] === $session_user_id) {
echo "This is you";
} else if (intval($friend_result) == 1) {
echo '<div class="removefriend">';
echo"Remove Friend";
echo '</div>';
} else if (intval($friend_result) == 0) {
echo '<div class="addfriend">';
echo"Add Friend";
echo '</div>';
}

echo "</div>";
echo "</div>";

//If statment to go here to see if already friends dont show add friends function also if current user is logged in sont show it. If already friends the option
//to remove the user as a fried becomes avalible

}

最佳答案

您的第二个查询没有 WHERE 子句,因此我看不到您如何列出与相关用户相关的 friend ,请将查询更改为:

SELECT user_id, friend_id, type FROM fyp_friends WHERE user_id = $usermain['user_id']

关于php - while 循环未运行 if 语句正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18522003/

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