gpt4 book ai didi

php - 具有独特提交按钮的 echo 阵列

转载 作者:行者123 更新时间:2023-11-29 08:32:10 26 4
gpt4 key购买 nike

基本上,此代码列出了“可用”挑战,其中 complete = 0 并在每个列表中都有一个接受submit 按钮。到目前为止,我一次只能列出一项,因为列出的多个按钮无法识别匹配 ID $echo 任何人都可以查看我的代码,看看我是否可以进行任何更改,以便我可以将 desc limit 101 更改,谢谢。

$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.'; }
}

这里

    ///$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 = '
<form action="multiplayer.php" method="POST">
<input type="radio" name="$echo" value="$echo">
';.' '.$button.'</td>
</tr>';
}
echo '</table>';
echo '<input type="submit" name="submit" value="Accept"></form>';

if (isset($_POST['submit'])) {
if (isset($_POST['$echo'])){
echo $echo;
}

最佳答案

更改你的代码,这完全是一团糟,例如你的 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\">";

但更好的是使用数组 $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,因为它们将来会被删除

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

回答您的问题时,您可以使用其他形式的输入,例如单选、复选框或隐藏,并将这些字段的值放入循环中,然后使用提交来发送它们。

关于php - 具有独特提交按钮的 echo 阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16296175/

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