我试图从表中显示两组数据。我正在为我的游戏开店,并且有一个数据库,列出商店中口袋妖怪的口袋妖怪/价格/类型/ ID。现在我几乎工作了,它显示了商店里的所有口袋妖怪,他们都有一个购买按钮,但由于某种原因无论你试图购买什么口袋妖怪,它只会购买列表顶部的那个。我希望我解释得很好,这是我的代码。
if ($_POST['A'] == '1' ) {
$token= mysql_real_escape_string($_POST['token']);
$tokenn = strip_tags($token);
$sql234 = "SELECT * FROM ticketshop";
$result2 = mysql_query("SELECT * FROM ticketshop");
while($row2 = mysql_fetch_array($result2)){
$sql23 = "SELECT * FROM users WHERE username='".$_SESSION['username']."')";
$result = mysql_query("SELECT * FROM users WHERE username='".$_SESSION['username']."'");
while($row = mysql_fetch_array($result)){
echo "You have ".$row['ticket']." Tickets" ;
echo "<p></p>" ;
if (isset($_POST['slot1'])) {
if ($row['ticket'] >= $row2['price']) {
echo "You have bought ".$row2['pokemon']."" ;
mysql_query("UPDATE users SET ticket=ticket-".$row2['price']." WHERE username='".$_SESSION['username']."'")
or die(mysql_error());
mysql_query("INSERT INTO user_pokemon
(pokemon, belongsto, exp, time_stamp, slot, level, type) VALUES ('".$row2['pokemon']."','".$_SESSION['username']."', 100,'".time()."','0', '5', '".$row2['type']."' )")
or die(mysql_error());
} else {
echo "You can't afford ".$row2['pokemon']."";
}
}
}
}