Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts

    New(ish) to PHP need a little help with IF / ELSE IF

    First and foremost... thanks in advance to anyone that can help me solve this easy issue.
    I have a gaming site that's PHP. There are different levels in which a player can achieve depending on the amount of credits they use...
    The problem I'm having is there are 2 factors in being level 3. So I would need 2 else if ($lvl==3) statements.

    One that looks like this:
    PHP Code:
    else if($lvl==3)
        
    $lvlstring="stats.credits>54999 And users.status='normal'" 
    and another that looks like this (once a supporter uses more than 74999 they move on to level 4 (which is for supporters ONLY)):
    PHP Code:
    else if($lvl==3)
        
    $lvlstring="stats.credits>54999 AND stats.credits<75000 And users.status='supporter" 
    The problem is... it never looks at the second ELSE IF statement... So supporters that are in level 3 just don't show up on the board.

    Any advice you can give... would be GREATLY appreciated!!

    Thanks
    Les-

  • #2
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    I wrote a previous message, but I reread your post a couple times, and I think I know what you're asking now. Basically, you are needing both of those MySQL statements to go in the query to find both "normal" users AND "supporter" users. If that's the case, do this:

    PHP Code:
    else if($lvl==3)
        
    $lvlstring="(stats.credits>54999 And users.status='normal') OR (stats.credits>54999 AND stats.credits<75000 And users.status='supporter)"
    Last edited by JohnDubya; 02-05-2010 at 07:11 PM.

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JohnDubya View Post
    I wrote a previous message, but I reread your post a couple times, and I think I know what you're asking now. Basically, you are needing both of those MySQL statements to go in the query to find both "normal" users AND "supporter" users. If that's the case, do this:

    PHP Code:
    else if($lvl==3)
        
    $lvlstring="(stats.credits>54999 And users.status='normal') OR (stats.credits>54999 AND stats.credits<75000 And users.status='supporter)"
    Sorry... I couldn't figure out the best way to word it... but yes you are correct I need both statements to go through SQL

    I tried that code and it returned the following error:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /public_html/game/prizes.php on line 113
    Line 113: is "$supResult = mysql_query($query);" but here's everything that leads up to that query:

    Here's that code:
    PHP Code:
    $query "SELECT $tab[player].id,$tab[player].name,$tab[player].networth,$tab[player].online,$tab[player].rank,$tab[player].nrank,$tab[player].status,$tab[player].online FROM users, stats,$tab[player] WHERE users.username = stats.user AND $tab[player].code=users.code AND stats.round='$tru' AND $lvlstring ORDER BY $tab[player].networth DESC limit 10";
          
    //echo $query;
          
    $supResult mysql_query($query);

          
    $i 1;
          while(
    $line mysql_fetch_array($supResult)){
              if(
    $rankstart==0){$rankcolor="#4A321A";$rankstart++;}
            elseif(
    $rankstart==1){$rankcolor="#6A4C24";$rankstart--;}

              
    $online=$time-$line[7];
              if (
    $online 600){$on="<img src=../images/online.gif width=16 height=16 align=absmiddle>";}else{$on='';}

              print(
    "<tr bgcolor=\"$rankcolor\"><td>$i</td>");
              print(
    "<td>$prize[$i]</td>");
              print(
    "<td>$on<a href=\"player.php?pid=$line[1]&tru=$tru\">$line[1]</a></td>");
              print(
    "<td>$".commas($line[2])."</td></tr>");
              
    $i++;
          }
      
    ?> 

  • #4
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    As a matter of debugging, you need to echo mysql_error() right after you do the query to see what the error is. That is the way to find out why MySQL failed on the query.

    Looks like you left off the closing quote mark after "supporter" in the variable. That would definitely do it.

    I also didn't realize you had other stuff in your WHERE clause. Since you do, you'll want to put parentheses around the entire $lvlstring text:

    PHP Code:
    $lvlstring="( (stats.credits>54999 AND users.status='normal') 
             OR 
             (stats.credits>54999 AND stats.credits<75000 AND users.status='supporter') )"


  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I'll give that a try... thanks for your input/help. I've been fighting with the crazy issue for a while now... thankfully someone referred me to this site!
    Thanks
    Les-

  • #6
    New Coder
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts
    OMG... that code you posted seems to work!!!
    I can't thank you enough, I've got to test it further to ensure everything is working at 100% (crossing fingers LOL).

    Over a month fighting this issue, question posted here and problem solved in first couple of hours. WOW

    Les-

  • #7
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Awesome, no prob, that's why we're here! I found this site through Google 3-4 years ago, and still love it. A great community of techy people.

  • Users who have thanked JohnDubya for this post:

    lesliegy (02-05-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •