Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:35:52+00:00 2026-06-14T20:35:52+00:00

I was suggested to ask this question again but with more depth. Here is

  • 0

I was suggested to ask this question again but with more depth.

Here is my script:

    <?php
    //Loggedin
    if($_SESSION['login']!=1)
    {
        print "You must be logged in.";
        include($root . 'footer.php');
        exit;
    }
    //Check banned account
    elseif($ui['level']=="2"){
        print "Sorry but your account is banned.";
        include($root . 'footer.php');
        exit;
    }
    //Check email verified
    elseif($ui['email_check']=="0"){
        print "Sorry but your account has not been verified, to verify your account now please visit <a href='index.php?index=verify&email=".$ui['email']."'>THIS LINK</a>.";
        include($root . 'footer.php');
        exit;
    }
date_default_timezone_set('America/New_York');
$country= $ui['country'];
$dates=mysql_query("SELECT * FROM `contest` WHERE `countries` LIKE '%$country%'");
$timestamp = time();

    $getcontests = $os_DB->query("SELECT * FROM contest WHERE date_1 <= '$timestamp' AND date_2 >= '$timestamp' AND countries LIKE '%$country%'");
        $num = $os_DB->num($getcontests);

            if($num == 0){
            print"<td colspan='4'>There are currently no active contests</td>";
            }
            else
            {

    while ($dat = mysql_fetch_array($dates)) {
        $tname = preg_replace('/\s+/', '', $dat['name']);
        $places="(SELECT * FROM `".$tname."_contest` WHERE `username` <> 'cassa' ORDER BY `completed` DESC LIMIT ".$dat['rewards'].")";
        $results=mysql_query($places) or die(mysql_error());




        $reward = array("".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4'].",".$dat['reward_5'].",".$dat['reward_6'].",".$dat['reward_7'].",".$dat['reward_8'].",".$dat['reward_9'].",".$dat['reward_10']."");

        $rewards = implode(",", $reward);

        $rewardsa = explode(",", $rewards);
        $i=0;
        $a=1;

            // Offers Contest

        if(time() <= $dat['date_2'] && time() >= $dat['date_1'] && $dat['type'] == offer) {
            print" <table width ='100%'><tr><th align='center'><font size='4'>{$dat['name']}</font></th><th align='right'><font size='1'>".date("m/d/Y h:i A", $dat['date_1'])."-".date("m/d/Y h:i A", $dat['date_2'])."</font></th></tr></table><br />".$dat['desc']."<br /><font size='1' color='white'>You must complete offers worth at least ".$dat['min_points']." points or $".$dat['min_cash']." to count towards contest!<br /><br />
            You must also complete at least ".$dat['min_offers']." offers in order to be eligible for winnings.</font><br /><br />";
            print" <table width ='100%'><tr><th align='left'>Place</th><th align='center'>User</th><th align='right'>Prize</th><th align='right'>Completed</th></tr>";

        if(mysql_num_rows($results) == 0){
            foreach($rewardsa as $rewa){
                if(!empty($rewa['$i'])){
                    if($dat['r_type'] == points){
                        print"  <tr><td align='left'>{$a}</td><td align='center'>......</td><td align='right'>{$rewardsa[$i]} points</td><td align='right'>--</td></tr>";
                    }
                if($dat['r_type'] == cash){
                    print"  <tr><td align='left'>{$a}</td><td align='center'>......</td><td align='right'>$".$rewardsa[$i]."</td><td align='right'>--</td></tr>";
                }
            $i++;
            $a++;
                }
            }
        }


    while ($place = mysql_fetch_array($results)) {
        if($dat['r_type'] == points){
            print"  <tr><td align='left'>{$a}</td><td align='center'>{$place['username']}</td><td align='right'>{$rewardsa[$i]} points</td><td align='right'>{$place['completed']}</td></tr>";
        }
        if($dat['r_type'] == cash){
            print"  <tr><td align='left'>{$a}</td><td align='center'>{$place['username']}</td><td align='right'>$".$rewardsa[$i]."</td><td align='right'>{$place['completed']}</td></tr>";
        }
        $i++;
        $a++;

    }
    ///Line I am working with///
    $getyou= mysql_query("SELECT COUNT(*) AS Place, t.*
    FROM ".$tname."_contest t
    GROUP BY t.id
    HAVING Place <= 3 OR username = '".$ui['username']."'");
        $youu = mysql_fetch_array($getyou);
        print"  <tr><td align='left'>{$youu['Place']}</td><td align='center'>You</td><td align='right'>---</td><td align='right'>{$youu['completed']}</td></tr>";
        }
    }
        }

?>  
        </table>

With this script I want to be able to show the logged user the place that they currently stand in the contest under the current winners.

This is what I want the table to look like.

-----------------------------------------
| Place |    User   | Prize | Completed |
|   1   | Someuser1 | $5.00 |     5     |
|   2   | Someuser2 | $2.50 |     3     |
|   3   | Someuser3 | $1.25 |     2     |
|   20  |    You    |  ---  |     1     |
-----------------------------------------

This is how it looks

-----------------------------------------
| Place |    User   | Prize | Completed |
|   1   | Someuser1 | $5.00 |     5     |
|   2   | Someuser2 | $2.50 |     3     |
|   3   | Someuser3 | $1.25 |     2     |
|   1   |    You    |  ---  |     1     |
-----------------------------------------

here is my table structure.

    Column   |  Type | Null |  Default
--------------------------------------
    id       |int(11)|  No  |   
    username |text   |  No  |   
    completed|int(11)|  No  |   

As you can see it is all coming from one table and the place isn’t defined by the database, but by the script itself.

Hopefully this can clarify more than my last question.

Edit: With Sean’s code this is what I get.

-----------------------------------------
| Place |    User    | Prize | Completed |
|   1   |   kikkat   | $5.00 |     1     |
|   2   |xXchris744Xx| $2.50 |     1     |
|   3   |  kira423   | $1.25 |     1     | /// This line is me
|   7   |    You     |  ---  |     1     | /// But it shows my current place as 7
-----------------------------------------
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:35:53+00:00Added an answer on June 14, 2026 at 8:35 pm

    This can be done with a nested query –

    $getyou= mysql_query("SELECT 
                            (SELECT count(*)+1 AS rank FROM contest WHERE completed >
                              (SELECT completed FROM contest WHERE username = '".$ui['username']."' ORDER BY completed DESC LIMIT 1)) as Place,
                            c.* FROM contest c WHERE username = '".$ui['username']."'");
    $youu = mysql_fetch_array($getyou);
        print"  <tr><td align='left'>{$youu['Place']}</td><td align='center'>You</td><td align='right'>---</td><td align='right'>{$youu['completed']}</td></tr>";
    

    Here is how the query works from the inside out-

    The 1st (inside) SELECT gets the completed amount for the username =$ui['username']

    SELECT completed FROM contest WHERE username = '".$ui['username']."' ORDER BY completed DESC LIMIT 1
    

    The 2nd (middle) SELECT uses that completed amount and does a count of all the rows that have more completed, adds a 1 to that count, and saves it as the users Place.

    SELECT count(*)+1 AS rank FROM contest WHERE completed > '#' // # represents the `completed` amount for the `$ui['username']` that we got in the 1st SELECT
    

    The 3rd/Last (outside) SELECT now just gets the row data for username =$ui['username']

    SELECT Place, c.* FROM contest c WHERE username = '".$ui['username']."'  // Place was created/defined in early SELECTS, now we just get the rest of the data using c.*
    

    Edit

    To add a tiebreaker when one or more have the same number completed, you need to order your query by the id as well. So change your first query to –

    $places="(SELECT * FROM `".$tname."_contest` WHERE `username` <> 'cassa' ORDER BY `completed`,`id` DESC LIMIT ".$dat['rewards'].")";
                                                                                                  ---
    

    And add ORDER BY id and >= to the 2nd query

    $getyou= mysql_query("SELECT 
                            (SELECT count(*)+1 AS rank FROM contest WHERE completed >=
                                                                                    --
                              (SELECT completed FROM contest WHERE username = '".$ui['username']."' ORDER BY completed DESC LIMIT 1) ORDER BY `completed`,`id`) as Place,
                                                                                                                                     -------------------------
                            c.* FROM contest c WHERE username = '".$ui['username']."'");
    

    Edit #2
    Try this new query. The previous one was not selecting the exact row, but the last of the tied.

    $getyou= mysql_query("SELECT Place, c.* FROM
                          (SELECT @Place:=@Place+1 AS Place, c.*
                            FROM contest c, (SELECT @Place := 0) r ORDER BY completed DESC, id ASC ) c
                             WHERE username = '".$ui['username']."'");
    

    This new query creates a temporary new column Place, using SELECT @Place := 0, and then we get the users ‘Place’ using @Place:=@Place+1 AS Place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

campbell suggested I ask a new question for this issue so here I go.
I asked a similar question in Code Review forum but was suggested to ask
Pretty new here. But before I ask my question, I'm not looking for teh
I have already asked this question on SuperUser but it was suggested there that
This looks so embarrassing and most awful to ask question again and again for
I hope this is okay to ask here as its more a request for
This question not probably not typical stackoverflow but am not sure where to ask
I'm not sure if this kind of question is appropriate, but its been suggested
This is a suggested re-up on a question I had before. Its really and
I don't quite know how to ask this question, so I'll phrase it as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.