...

View Full Version : New(ish) to PHP need a little help with IF / ELSE IF



lesliegy
02-05-2010, 07:58 PM
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:


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)):


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-

JohnDubya
02-05-2010, 08:06 PM
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:



else if($lvl==3)
$lvlstring="(stats.credits>54999 And users.status='normal') OR (stats.credits>54999 AND stats.credits<75000 And users.status='supporter)";

lesliegy
02-05-2010, 08:44 PM
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:



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 :D

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:


$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++;
}
?>

JohnDubya
02-05-2010, 09:22 PM
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:



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

lesliegy
02-05-2010, 11:23 PM
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-

lesliegy
02-05-2010, 11:29 PM
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:thumbsup:

Les-

JohnDubya
02-05-2010, 11:29 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum