2

I am making Tournament mod. And I do not know how to correctly do some operations with fetched array.

What my code is doing, is that it takes data from Tournament table and add it to array. Then print it in HTML table, so all users can see the place where he has. How can I correctly get the first, second, third array data for the first 3 winners and give them a price? And how can I deal with players who have the same amount of points?
Right now the query below seems to not work too, all statements are positiv and it should execute the function.

if($counter == 1) {
    $GLOBALS['DATABASE']->query("UPDATE  ".USERS." SET `atm` = `atm` + 20000  WHERE `id` = ".$recordRow['id_owner']." ;");
}

Sorry, my English is not good and I tried to search for the answers but didn't find anything, because i do not know for what PHP solution should i search.

My code:

$recordFetch = $GLOBALS['DATABASE']->query("SELECT *FROM `uni1_tournament` ORDER BY wons DESC;");
$counter = 0;
$RangeList  = array();
while ($recordRow = $GLOBALS['DATABASE']->fetch_array($recordFetch)) {
    $counter += 1;
    $RangeList[]    = array(
        'id'        => $recordRow['id_owner'],
        'name'      => $recordRow['name'],
        'points'        => $recordRow['wons']*5,
        'counter'       => $counter,
    );

    if($t_time > TIMESTAMP) {
        if($counter == 1) {
            $GLOBALS['DATABASE']->query("UPDATE  ".USERS." SET `atm` = `atm` + 20000  WHERE `id` = ".$recordRow['id_owner']." ;");
        }
        elseif($counter == 2) {
            //to do;
        } elseif($counter == 3) {
            //to do;
        }               
    }   
}
2

2 Answers 2

1
  • Make query like this "select * from uni1_tournament GROUP BY points ORDER BY points desc limit 3";
Sign up to request clarification or add additional context in comments.

Comments

1

If you're using regular mysql or mysqli (been a while since I have for either, moved to doctrine a while back), fetch_array needs to be ran on the results and not the GLOBALS['DATABASE'] variable (guessing this a global variable for the database connection).

Try changing

while ($recordRow = $GLOBALS['DATABASE']->fetch_array($recordFetch)) {

to

while ($recordRow = $recordFetch->fetch_array()) {

In order to use your original formatting, I believe fetch_array needed to be mysqli_fetch_array instead.

i.e

while ($recordRow = $GLOBALS['DATABASE']->mysqli_fetch_array($recordFetch)) {

1 Comment

I have DB class what use MYSQLI functions. Also i remake the first answer a bit and i get what i needed. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.