我需要一些帮助。我正在this页面上工作,我想知道如何显示与nick变量匹配的所有STEAMID和Nicknames。我目前使用LIKE ='%$ nick%'来查找匹配的昵称,但如果两个玩家被称为Sidewaykill,它只会显示一个,但我希望它显示全部。我并不真正关心它的外观,只要它显示所有匹配的玩家Nicknames和STEAMID。谢谢。
<?php
//Get STEAMID from steamid variable
$nick = mysql_escape_string(stripslashes($_GET["nick"]));
$steamid = $_GET["steamid"];
?>
<!DOCTYPE html>
<html><head><title>Searching for a player steamid</title>
</head>
<body>
<?php
//Connect to database
$sqluser = "----";
$sqlpass = "----";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $sqluser, $sqlpass)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("versound_store",$dbhandle)
or die("Could not select database!");
//Attempt to find player SteamID
$sql1 = "SELECT steamid FROM `vxp_users` WHERE nick LIKE '%$nick%'";
$res1 = mysql_query($sql1) or trigger_error(mysql_error());
$row1 = mysql_fetch_assoc($res1);
$steamid2 = $row1['steamid'];
//Find latest recorded Nickname
$sql2 = "SELECT nick FROM `vxp_users` WHERE steamid = '$steamid2'";
$res2 = mysql_query($sql2) or trigger_error(mysql_error());
$row2 = mysql_fetch_assoc($res2);
$nick23 = $row2['nick'];
if (!empty($steamid2)) {
//Write Info
echo $nick23;
echo ' - ';
echo $steamid2;
//echo '<br /><br />Last Recorded Steam Name: ';
//echo '<br /><br />Current Steam Name: ';
//echo $currentsteamname;
echo '<br /><br /><a href="http://versound.org/finder/steamidtoprofile.php?steamid=';
echo $steamid2;
echo '" target="_blank">Link to Steam Profile</a>';
}
else
{
echo 'The player ';
echo '"';
echo $nick;
echo '"';
echo ' was not found in the database. Make sure you have correctly entered their nickname.';
}
?>
</body>
</html>
答案 0 :(得分:1)
你需要循环:
while ($row1 = mysql_fetch_assoc($res1)) {
echo $row1['steamid']; // or store in an array etc.
}
答案 1 :(得分:1)
你有这条线:
$row2 = mysql_fetch_assoc($res2);
您应该用循环替换它。每当你打电话给mysql_fetch_assoc()
时,它都会带来下一行 - 所以你会使用这样的东西:
while ($row = mysql_fetch_assoc($res2)) {
有关详细信息,请参阅the documentation。
警告:这些函数已从PHP 5.5弃用 - 从长远来看,使用mysqli
或PDO
可以让您有更好的时间。