许多ID的一种形式

时间:2013-05-31 15:21:12

标签: php

我试图从表中显示两组数据。我正在为我的游戏开店,并且有一个数据库,列出商店中口袋妖怪的口袋妖怪/价格/类型/ 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']."";
}
}
}
}

1 个答案:

答案 0 :(得分:1)

您收到错误是因为您正在关闭与数据库的连接,并且在您尝试从第二个查询中获取结果时结果出现错误

<?php } /* mysql_close($conn);*/ /*comment or remove closing connection*/ ?>

<p><b>Listing of pending applications</b></p>

然后我想要记住,mysql_函数已被弃用,因此我建议您切换到mysqliPDO