1

如果有 4 个按钮,我如何在下面的代码中获取随机项目的价格并根据单选按钮选择插入到 mysql 中:

$class1 = array("Peugeot 404"=>5000,"Opel Diplomat"=>7500,"Honda Civic"=>10000,"Renault Megane"=>15000);
$class2 = array("Ford Mustang"=>22500,"Dodge Charger"=>36000,"Alfa GTV "=>90000,"Aston Martin Vanquish"=>102000);
$class3 = array("BMW 7 series"=>114000,"Ferrari F430"=>132000,"Pagani Zonda"=>150000,"Maserati Gran Turismo"=>168000);
$class4 = array("Bentley Continental R"=>180000,"Maybach"=>200000,"Rolls-Royce Phantom"=>300000);

$rand1 = array_rand($class1,4);
$rand2 = array_rand($class2,4);
$rand3 = array_rand($class3,4);
$rand4 = array_rand($class4,3);

if($_POST['do'])
{
    echo $_POST['car'];
}
?>
<form method="POST">
<input type="radio" name="car" id="<? $rand1 ?>" value="<? echo "You have won: ".$rand1[0]." AND Price: ".$class1[$rand1[0]].""; ?>" />Class 1<br />
<input type="radio" name="car" id="<? $rand2 ?>" value="<? echo "You have won: ".$rand2[0]." AND Price: ".$class2[$rand2[0]].""; ?>" />Class 2<br />
<input type="radio" name="car" id="<? $rand3 ?>" value="<? echo "You have won: ".$rand3[0]." AND Price: ".$class3[$rand3[0]].""; ?>" />Class 3<br />
<input type="radio" name="car" id="<? $rand4 ?>" value="<? echo "You have won: ".$rand4[0]." AND Price: ".$class4[$rand4[0]].""; ?>" />Class 4<br />
<input type="submit" name="do" value="DO" />
</form> 

这就像一个黑手党游戏,当我选择第一个单选按钮时,我会随机获得一辆带有价格的汽车。第二个按钮也给了我一件随机汽车,但其他车型。

之后我需要将它插入到 mysql DB 中。

4

0 回答 0