Note that there are some explanatory texts on larger screens.

plurals
  1. POAward different amounts by place (PHP)
    text
    copied!<p>What I am trying to do is create a contest script for a GPT site, and I want to be able to award the winners with different amounts that are defined in the database. For example first place would get what <code>reward_1</code> is in the data base and so on. So I am trying to make it to where when I do <code>mysql_query("UPDATE members SET points=points+'$reward' WHERE username='$username'")</code> but I need <code>$reward</code> to be different for each of the winning users.</p> <p><strong>CLARIFICATION</strong><br> When this specific script is ran it gives out the rewards to the users if the date is >= the end date of the contest (in the code it says &lt;= because if not I wouldn't be able to test it) but basically when it gives out the rewards I want to be able to use 1 query to do so but I want that query to give out the right rewards to the right users. For example the user who completed the most offers should get what reward_1 in the contest table says which lets say is 1000 and the second place user will get what the reward is listed as for row reward_2 like 500. The way I have it set up now it will give the same reward amount to all users instead of a different amount to each. I hope that helps! </p> <p>Here is the code I have (please note that I haven't added any functions to attempt to do this as I have no idea where to start)</p> <p><strong>UPDATE</strong><br> What I am working with is what is after all of the blocked lines and the reward amounts will be coming from the dbtable contest.</p> <p>I am not sure if I have given enough of a description of what I am trying to get so if I need to clarify on anything please let me know, all your help is appreciated!</p> <p>Okay so I have been working on this a little bit, trying to use arrays, please excuse this sloppiness as I am only trying to possibly get things working the way I need it to! This is the new code:</p> <pre><code>&lt;? include_once"config.php"; date_default_timezone_set('UTC'); $query= "SELECT * FROM raffle WHERE amount&gt;='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 // &lt;br /&gt;User Name = $username // &lt;hr /&gt;"; // $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' =&gt; $dat['reward_1']); } else if ($dat['rewards'] == 2){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2']); } else if ($dat['rewards'] == 3){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3']); } else if ($dat['rewards'] == 4){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3'], '4' =&gt; $dat['reward_4']); } else if ($dat['rewards'] == 5){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3'], '4' =&gt; $dat['reward_4'], '5' =&gt; $dat['reward_5']); } else if ($dat['rewards'] == 6){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3'], '4' =&gt; $dat['reward_4'], '5' =&gt; $dat['reward_5'], '6' =&gt; $dat['reward_6']); } else if ($dat['rewards'] == 7){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3'], '4' =&gt; $dat['reward_4'], '5' =&gt; $dat['reward_5'], '6' =&gt; $dat['reward_6'], '7' =&gt; $dat['reward_7']); } else if ($dat['rewards'] == 8){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3'], '4' =&gt; $dat['reward_4'], '5' =&gt; $dat['reward_5'], '6' =&gt; $dat['reward_6'], '7' =&gt; $dat['reward_7'], '8' =&gt; $dat['reward_8']); } else if ($dat['rewards'] == 9){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3'], '4' =&gt; $dat['reward_4'], '5' =&gt; $dat['reward_5'], '6' =&gt; $dat['reward_6'], '7' =&gt; $dat['reward_7'], '8' =&gt; $dat['reward_8'], '9' =&gt; $dat['reward_9']); } else if ($dat['rewards'] == 10){ $reward = array ('1' =&gt; $dat['reward_1'], '2' =&gt; $dat['reward_2'], '3' =&gt; $dat['reward_3'], '4' =&gt; $dat['reward_4'], '5' =&gt; $dat['reward_5'], '6' =&gt; $dat['reward_6'], '7' =&gt; $dat['reward_7'], '8' =&gt; $dat['reward_8'], '9' =&gt; $dat['reward_9'], '10' =&gt; $dat['reward_10']); } while ($place = mysql_fetch_array($places)) { if(time() &lt;= strtotime($dat['date_2'])) { foreach($reward as $rew) print" {$dat['name']} {$place['username']} {$rew} &lt;br&gt;"; } else { print" no contests ready for rewards given"; } } } ?&gt; </code></pre> <p>It kind of gives me the results I want, but it duplicates it for each so it gives me:</p> <pre><code>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 </code></pre> <p>Which is repeating the 3 rewards for each winner, but I need it to look like this:</p> <pre><code>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 </code></pre> <p>Maybe arrays aren't the best fix for this, but if it is, I guess I need to know how to make it look like the table above rather than the first one that it is giving me now.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload