我要做的是为 GPT 网站创建一个竞赛脚本,并且我希望能够以数据库中定义的不同金额奖励获奖者。例如,第一名将获得reward_1
数据库中的内容等等。因此,我正在努力做到当我做的时候,mysql_query("UPDATE members SET points=points+'$reward' WHERE username='$username'")
但我需要$reward
对每个获胜的用户有所不同。
澄清
当这个特定脚本运行时,如果日期> =比赛的结束日期,它会给用户奖励(在代码中它说<=因为如果不是我将无法测试它)但基本上当它给出奖励时,我希望能够使用 1 个查询来执行此操作,但我希望该查询向正确的用户提供正确的奖励。例如,完成最多报价的用户应该得到比赛表中的reward_1,假设是1000,第二名的用户将得到列reward_2的奖励,比如500。我现在设置的方式它将为所有用户提供相同的奖励金额,而不是给每个用户不同的奖励金额。我希望这会有所帮助!
这是我的代码(请注意,我没有添加任何函数来尝试这样做,因为我不知道从哪里开始)
更新
我正在处理的是在所有被阻止的行之后,奖励金额将来自 dbtable 比赛。
我不确定我是否已经对我想要得到的内容进行了足够的描述,所以如果我需要澄清任何事情,请告诉我,感谢您的所有帮助!
好的,所以我一直在努力解决这个问题,尝试使用数组,请原谅这种草率,因为我只是想让事情按照我需要的方式工作!这是新代码:
<?
include_once"config.php";
date_default_timezone_set('UTC');
$query= "SELECT * FROM raffle WHERE amount>='1' ORDER BY Rand() LIMIT 2";
$result = mysql_query($query);
$raff=mysql_query("SELECT SUM(amount) FROM raffle");
$raffle=mysql_fetch_row($raff);
$amount= $raffle[0] / 2;
$dates= mysql_query("SELECT * FROM contest");
$stats= mysql_query("SELECT * FROM stats WHERE type='today'");
$statu= mysql_fetch_array($stats);
// while ($row = mysql_fetch_array($result)){
// $uid = $row["id"];
// $username = $row["user_id"];
// echo "User ID = $uid
// <br />User Name = $username
// <hr />";
// $winners= mysql_query("UPDATE members SET points=points+'".$amount."' WHERE username='".$username."'");
// $statusu1= mysql_query("UPDATE stats SET new='".$statu['new']."' WHERE type='yesterday'");
// $statusu2= mysql_query("UPDATE stats SET cashouts='".$statu['cashouts']."' WHERE type='yesterday'");
// $statusu3= mysql_query("UPDATE stats SET complete='".$statu['complete']."' WHERE type='yesterday'");
// $announce= mysql_query("INSERT INTO comment (text, home, date, text1)
// VALUES ('Rewards Cube System','',NOW(),'".$username." just won ".$amount." points in the daily raffle, Congrats!')");
// }
// $clear= mysql_query("UPDATE raffle SET amount='0'");
// $clear1= mysql_query("UPDATE stats SET new='0' WHERE type='today'");
// $clear2= mysql_query("UPDATE stats SET cashouts='0' WHERE type='today'");
// $clear3= mysql_query("UPDATE stats SET complete='0' WHERE type='today'");
// print" DONE";
while ($dat = mysql_fetch_array($dates)) {
$places= mysql_query("SELECT * FROM members ORDER BY entries_".$dat['type']." DESC LIMIT ".$dat['rewards']."");
if ($dat['rewards'] == 1){
$reward = array ('1' => $dat['reward_1']);
}
else if ($dat['rewards'] == 2){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2']);
}
else if ($dat['rewards'] == 3){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3']);
}
else if ($dat['rewards'] == 4){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3'], '4' => $dat['reward_4']);
}
else if ($dat['rewards'] == 5){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3'], '4' => $dat['reward_4'], '5' => $dat['reward_5']);
}
else if ($dat['rewards'] == 6){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3'], '4' => $dat['reward_4'], '5' => $dat['reward_5'], '6' => $dat['reward_6']);
}
else if ($dat['rewards'] == 7){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3'], '4' => $dat['reward_4'], '5' => $dat['reward_5'], '6' => $dat['reward_6'], '7' => $dat['reward_7']);
}
else if ($dat['rewards'] == 8){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3'], '4' => $dat['reward_4'], '5' => $dat['reward_5'], '6' => $dat['reward_6'], '7' => $dat['reward_7'], '8' => $dat['reward_8']);
}
else if ($dat['rewards'] == 9){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3'], '4' => $dat['reward_4'], '5' => $dat['reward_5'], '6' => $dat['reward_6'], '7' => $dat['reward_7'], '8' => $dat['reward_8'], '9' => $dat['reward_9']);
}
else if ($dat['rewards'] == 10){
$reward = array ('1' => $dat['reward_1'], '2' => $dat['reward_2'], '3' => $dat['reward_3'], '4' => $dat['reward_4'], '5' => $dat['reward_5'], '6' => $dat['reward_6'], '7' => $dat['reward_7'], '8' => $dat['reward_8'], '9' => $dat['reward_9'], '10' => $dat['reward_10']);
}
while ($place = mysql_fetch_array($places)) {
if(time() <= strtotime($dat['date_2'])) {
foreach($reward as $rew)
print" {$dat['name']} {$place['username']} {$rew} <br>";
}
else {
print" no contests ready for rewards given";
}
}
}
?>
它给了我想要的结果,但是它为每个结果都复制了它,所以它给了我:
Monthly Offer Contest Faiz66 2500
Monthly Offer Contest Faiz66 1000
Monthly Offer Contest Faiz66 500
Monthly Offer Contest taras 2500
Monthly Offer Contest taras 1000
Monthly Offer Contest taras 500
Monthly Offer Contest admin 2500
Monthly Offer Contest admin 1000
Monthly Offer Contest admin 500
Monthly Referral Contest taras 2500
Monthly Referral Contest taras 1000
Monthly Referral Contest taras 500
Monthly Referral Contest kira423 2500
Monthly Referral Contest kira423 1000
Monthly Referral Contest kira423 500
Monthly Referral Contest Faiz66 2500
Monthly Referral Contest Faiz66 1000
Monthly Referral Contest Faiz66 500
这是为每个获胜者重复 3 个奖励,但我需要它看起来像这样:
Monthly Offer Contest Faiz66 2500
Monthly Offer Contest taras 1000
Monthly Offer Contest admin 500
Monthly Referral Contest taras 2500
Monthly Referral Contest kira423 1000
Monthly Referral Contest Faiz66 500
也许数组不是解决这个问题的最佳方法,但如果是,我想我需要知道如何让它看起来像上面的表格,而不是它现在给我的第一个表格。