具有唯一提交按钮的回声数组

时间:2013-04-30 09:10:42

标签: php mysql

基本上,此代码会列出“可用”质询,其中complete = 0并且每个商家信息都包含一个接受submit按钮。到目前为止,我一次只能列出一个项目,因为列出的多个按钮无法识别匹配ID $echo任何人都可以查看我的代码并查看是否可以进行任何更改以便我可以更改{{1来自desc limit 10谢谢。

1

下面

$query = mysql_query("SELECT `create_id` ,`value`, `player1`, `match_id` FROM `multiplayer` WHERE `complete` = 0 ORDER BY `value` DESC LIMIT 1");
echo '<table>';
while($rowtwo = mysql_fetch_array($query)){
    $format_coins = number_format($rowtwo['value']);
    $value = $rowtwo['value'];
    $create_player = $rowtwo['player1'];
    $echo = $rowtwo['match_id'];
    $create_id = $rowtwo['create_id'];
    $button =   '<form action="multiplayer.php" method="POST"><input type="submit" name="'.$echo.'" value="Accept"></form>';
    ///$button = '<a href="match/'.$echo.'.php">Accept</a>';
    echo   '<tr>
            <td><font size="2" face="Lucida Sans Unicode"><strong>'.$rowtwo['player1'].'</strong> has wagered '.$format_coins.'M/Gp   '.$button.'</td>
            </tr>';
}
echo '</table>';
if (isset($_POST[''.$echo.''])) {
    if ($user_data['coins'] >= $value) {
        if ($user_data['user_id'] == $create_id) {
            echo 'You can\'t play yourself.';
        } else {    
                    $betadd = $user_data['bets'] + 1;
                    mysql_query("UPDATE `users` SET `bets` = $betadd WHERE `user_id` = $user_id");
                    $rand1 = rand(1, 5);$rand2 = rand(1, 5);$rand3 = rand(1, 5);$rand4 = rand(1, 5);$rand5 = rand(1, 5);$rand6 = rand(1, 5);$rand7 = rand(1, 5);$rand8 = rand(1, 5);$rand9 = rand(1, 5);$rand10 = rand(1, 5);
                    echo '<font size="2"><strong>You\'ve</strong> planted : <br></font>';
                    if ($rand1 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand1 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand1 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand1 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand1 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand2 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand2 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand2 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand2 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand2 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand3 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand3 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand3 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand3 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand3 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand4 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand4 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand4 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand4 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand4 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand5 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand5 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand5 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand5 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand5 === 5) {echo '<img src="images/Flowers_(pastel).png">';}                     
                    $userscore = counting(array($rand1, $rand2, $rand3, $rand4, $rand5));
                    echo '<br>';
                    echo '<font size="2"><strong>'.$create_player.'</strong> planted : <br></font>';
                    if ($rand6 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand6 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand6 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand6 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand6 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand7 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand7 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand7 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand7 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand7 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand8 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand8 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand8 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand8 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand8 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand9 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand9 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand9 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand9 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand9 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand10 === 1){     echo '<img src="images/Red_flowers.png">';} else if ($rand10 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand10 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand10 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand10 === 5) {echo '<img src="images/Flowers_(pastel).png">';}                     
                    //echo '<br>';
                    $hostscore = counting(array($rand6, $rand7, $rand8, $rand9, $rand10));
                    mysql_query("UPDATE `multiplayer` SET `rand1` = $rand1 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand2` = $rand2 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand3` = $rand3 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand4` = $rand4 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand5` = $rand5 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand6` = $rand6 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand7` = $rand7 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand8` = $rand8 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand9` = $rand9 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `rand10` = $rand10 WHERE `match_id` = $echo");
                    echo '<br>';
                    echo '<br>';
                    if ($userscore > $hostscore) {
                        echo 'You win';
                        $username = $user_data['username'];
                        $userid = $user_data['user_id'];
                        mysql_query("UPDATE `users` SET `multi` = 0 WHERE `user_id` = $create_id");
                        mysql_query("UPDATE `multiplayer` SET `complete` = 1 WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `score1` = $hostscore WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `score2` = $userscore WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `player2` = '$username' WHERE `match_id` = $echo");
                        $coins = $user_data['coins'] + $value;
                        mysql_query("UPDATE `users` SET `coins` = $coins WHERE `user_id` = $userid");
                    } else if ($userscore == $hostscore) {
                        echo 'You\'ve Tied';
                        $username = $user_data['username'];
                        mysql_query("UPDATE `users` SET `multi` = 0 WHERE `user_id` = $create_id");
                        mysql_query("UPDATE `multiplayer` SET `complete` = 1 WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `score1` = $hostscore WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `score2` = $userscore WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `player2` = '$username' WHERE `match_id` = $echo");
                        $hostcoins = mysql_query("SELECT `coins` FROM `users` WHERE `user_id` = $create_id");
                        $hostpayback = $hostcoins + $value;
                        mysql_query("UPDATE `users` SET `coins` = $hostpayback WHERE `user_id` = $create_id");
                    } else if ($userscore < $hostscore) {
                        echo 'You\'ve Lost.';
                        $username = $user_data['username'];
                        $userid = $user_data['user_id'];
                        mysql_query("UPDATE `users` SET `multi` = 0 WHERE `user_id` = $create_id");
                        mysql_query("UPDATE `multiplayer` SET `complete` = 1 WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `score1` = $hostscore WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `score2` = $userscore WHERE `match_id` = $echo");
                        mysql_query("UPDATE `multiplayer` SET `player2` = '$username' WHERE `match_id` = $echo");
                        $hostcoins = mysql_query("SELECT `coins` FROM `users` WHERE `user_id` = $create_id");
                        $hostpayback = $hostcoins + ($value * 2);
                        mysql_query("UPDATE `users` SET `coins` = $hostpayback WHERE `user_id` = $create_id");
                        $coins = $user_data['coins'] - $value;
                        mysql_query("UPDATE `users` SET `coins` = $coins WHERE `user_id` = $userid");
                    }
        }
    } else { echo 'You can\'t afford to enter this match.'; }
}

1 个答案:

答案 0 :(得分:2)

将您的代码更改为完全混乱,例如您的ifs

 if ($rand1 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand1 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand1 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand1 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand1 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                if ($rand2 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand2 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand2 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand2 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand2 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                if ($rand3 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand3 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand3 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand3 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand3 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                if ($rand4 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand4 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand4 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand4 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand4 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                if ($rand5 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand5 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand5 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand5 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand5 === 5) {echo '<img src="images/Flowers_(pastel).png">';}      

可以写

$color="";
if($rand1 === 1||$rand2=== 1||$rand3=== 1||$rand4=== 1||||$rand5===1) $color="Red";   
else if($rand1 === 2||$rand2=== 2||$rand3=== 2||$rand4=== 2||||$rand5===2) $color="Blue";

echo "<img src=\"images/$color_flowers.png\">";

但更好的方法是使用array $ rand = array();并访问它们$ rand [0],$ rand [1];等

与mysql_updates相同

mysql_query("UPDATE `users` SET `multi` = 0 WHERE `user_id` = $create_id");
                    mysql_query("UPDATE `multiplayer` SET `complete` = 1 WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `score1` = $hostscore WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `score2` = $userscore WHERE `match_id` = $echo");
                    mysql_query("UPDATE `multiplayer` SET `player2` = '$username' WHERE `match_id` = $echo");

可以更改为

 mysql_query("UPDATE `multiplayer` SET `complete` = 1, score1=$hostscore, score2=$userscore, player2=$username WHERE `match_id` = $echo");

但是 mysql_ *函数已经过时我建议将它们更改为PDO,因为它们将来会被删除

使用转义函数和转换,因为您的脚本不安全!!

回答你的问题,你可以使用其他形式的输入,如收音机,复选框或隐藏,并将值放在循环中这些字段,然后使用提交发送它们。