0

我想搜索我的名为 users 的 SQL 表,如果他们在名为 gangs 的结构中有结果,那么如果该结果是我要查找的结果,则在列表中显示所有找到的结果。这是我到目前为止的代码,女巫无法正常工作,请帮助谢谢

$sql = "SELECT * FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
$userip = htmlspecialchars($row->userip);
$name = htmlspecialchars($row->name);
$sitestate = htmlspecialchars($row->sitestate);
$password = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);
$money = htmlspecialchars($row->money);
$exp = htmlspecialchars($row->exp);
$rank = htmlspecialchars($row->rank);
$health = htmlspecialchars($row->health);
$points = htmlspecialchars($row->points);
$profile = htmlspecialchars($row->profile);
$gang = htmlspecialchars($row->gang);

<?php 
$sql = "SELECT * FROM Gangs WHERE name='".mysql_real_escape_string($_GET['name'])."'";
$query = mysql_query($sql)  or die(mysql_error());
$row = mysql_fetch_object($query);
$Gang_name = htmlspecialchars($row->name);
$Gang_owner = htmlspecialchars($row->owner);
$Gang_money = htmlspecialchars($row->money);
$Gang_exp = htmlspecialchars($row->exp);
$Gang_level = htmlspecialchars($row->level);
$Gang_profile = htmlspecialchars($row->profile);
?>

<?php
$result = mysql_query("SELECT * FROM users WHERE gang = '".$gang_name."'");
if ($result) {
      while($row = mysql_fetch_assoc($result)) {
           $members = $row['name'];
      }
}
?>
<?php echo $members; ?>
4

1 回答 1

2

看起来您应该只使用带有连接的 SELECT 查询

"SELECT * FROM users as u JOIN gangs as g on u.gang = g.name WHERE g.name = '".mysql_real_escape_string($_GET['name'])."'";

如果您正在尝试构建结果行数组,则:

$members = $row['name'];

应该:

$members[] = $row['name'];

您还应该在循环之前声明您的 $memberes 变量,例如

$members = array();
于 2012-08-02T20:35:03.667 回答