gpt4 book ai didi

当有更多结果时,Php/Mysql 搜索仅返回 1 个结果

转载 作者:行者123 更新时间:2023-11-29 14:12:10 24 4
gpt4 key购买 nike

我在脚本中进行了双重搜索。当它搜索玩家装备时,它将获取玩家 UID 并带回该玩家的姓名。唯一的问题是可能会返回超过 1 个结果,并且只会显示最后一个带有该名称的 UID。

$ip = "localhost";
$user = "******";
$pass = "*******";
$db = "hivemind";
$ill1 = $_POST['search'];

//Database Connection
$con = @mysql_connect("$ip:3316", "$user", "$pass")
or die(mysql_error());

//Select Database
$dbcon = @mysql_select_db($db, $con)
or die(mysql_error());

$sql = mysql_query("select PlayerUID, Inventory, Backpack from character_data where Inventory like '%$ill1%'");

while ($row = mysql_fetch_array($sql)) {
$puid = $row['PlayerUID'];
$inv = $row['Inventory'];
$back = $row['Backpack'];
?>
<html>
<body>
<table>
<tr>

<td><?php echo "$puid"; ?></td>
<td><?php echo "$inv"; ?></td>
<td><?php echo "$back"; ?></td>

</tr>
</table>
</body>
</html>
<?php }?>

<?php

//Database Connection
$con = @mysql_connect("$ip:3316", "$user", "$pass")
or die(mysql_error());

//Select Database
$dbcon = @mysql_select_db($db, $con)
or die(mysql_error());

$sql = mysql_query("select PlayerUID, PlayerName from player_data where PlayerUID like '%$puid%'");

while ($row = mysql_fetch_array($sql)) {

$puid2 = $row['PlayerUID'];
$plnm = $row['PlayerName'];
?>
<html>
<body>
<table>
<tr>
<td><?php echo "$puid"; ?></td>
<td><?php echo "$plnm"; ?></td>


</tr>
</table>
</body>
</html>
}

最佳答案

它正在返回所有结果。您没有正确打印它们。

将 html、body、table 标签移到 while 循环之外。

将循环更改为:

while ($row = mysql_fetch_array($sql)) {

$puid2 = $row['PlayerUID'];
$plnm = $row['PlayerName'];
echo "<tr><td>".$puid."</td>";
echo "<td>".$plnm."</td></tr>";
}

关于当有更多结果时,Php/Mysql 搜索仅返回 1 个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13303209/

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