为会话用户创建变量时遇到问题。我正在创建一个练习拳击网站,将会话用户与具有相同属性(即体重)的人进行匹配
<?php
session_start();
include "connection.php";
$id = $_GET["userID"];
$sql = "SELECT * FROM userdetails WHERE userID = '" . $id . "'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo"<div>" .
"<br>First name: " . $row["firstname"] .
"<br>Second name: " . $row["secondname"] .
"<br>Mobile: " . $row["mobile"] .
"<br>Height: " . $row["height"] . "CM" .
"<br>weight: " . $row["weight"] . "KG" .
"<br>Image:<br> <img src=getimage.php?
userID=" . $row["userID"] . "width=100, height=100" .
"<br> You are a match! click below to view events" .
"<br><a href=Events.php?userID=" . $row["userID"] . ">View
Events</a>" .
"</div>";
}
} else {
echo"0 results";
}
$weight = $row['weight'];
?>
此代码允许我收集和显示表中个人的数据,$weight=$row['weight'];行将个体的权重放入变量中。
我不确定如何将会话用户的权重放入一个变量中,然后如何比较两者。我想我需要一个if语句。比如:
if ($weight == $sessionusersweight){
echo "you're a match";
}
else{
echo "you're not a match";
}
任何帮助都将不胜感激
3条答案
按热度按时间axzmvihb1#
我建议的第一件事是首先使用打开:
然后插入所需的所有代码,一旦完成,您需要的是将行的值赋给变量,这样您就可以执行以下操作:
2nbm6dog2#
因此,会话中有一个用户。如果是这样,那么您可以从
$_SESSION
变量。要在会话中存储数据,可以执行以下操作:
现在,您的行数据在
$_SESSION
变量asuser
索引。从中获取用户$_SESSION
您可以按以下步骤操作:在这里,
session_start()
方法用于启动会话。在同一个文件中不需要两次。然后您可以随意查看:
neskvpey3#
我给你做了一个版本,我认为这是你想要(这不是太明显)实现的。