kendallkamikaze Posted June 15, 2009 Share Posted June 15, 2009 Alright so I've been tampering with this code, and the first portion of it works if you meet the variables, but if you dont [the echo] it doesnt work...any tips? <?php $AcademyLevel = $r['AcademyLevel']; $mStatus = $r['Status']; $AcademyLevel = $r['AcademyLevel']; //echo "MS: ".$mStatus; $sql = "SELECT * FROM player WHERE id='$id'"; $resultA = mysql_query($sql) or die(mysql_error()); if(($mStatus == "mod" || $mStatus == "Diamond") && $AcademyLevel > 4){ if (mysql_num_rows($resultA) > 0) { echo "<BR><TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center><a href='lab_home.php'>Use Your Lab!</a></center></td></table><BR><table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association? <BR><BR><a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table>"; } else echo "<table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association?<BR><BR> <a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table><BR><BR> <TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center>You must be Academy level 5 to access the Lab.</center></td></table>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/ Share on other sites More sharing options...
Ken2k7 Posted June 15, 2009 Share Posted June 15, 2009 You left out a closing curly brace "}" before the else statement. What I think you want to do is move the curly brace at the end to before the else. If you look closely, you see that you never closed your first if statement. You closed the second one, which is the one containing the mysql_num_rows function. Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-855992 Share on other sites More sharing options...
kendallkamikaze Posted June 15, 2009 Author Share Posted June 15, 2009 hmm by adding another } it: Parse error: syntax error, unexpected '}' in /home4/collegh9/public_html/one-stride/player_diamond.php on line 222 Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-855996 Share on other sites More sharing options...
Ken2k7 Posted June 15, 2009 Share Posted June 15, 2009 Post an updated version of the code. Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-855998 Share on other sites More sharing options...
kendallkamikaze Posted June 15, 2009 Author Share Posted June 15, 2009 Alright so I got it to not throw an error, but its still not printing the else statement if it does not meet the variable. <?php $AcademyLevel = $r['AcademyLevel']; $mStatus = $r['Status']; $AcademyLevel = $r['AcademyLevel']; //echo "MS: ".$mStatus; $sql = "SELECT * FROM player WHERE id='$id'"; $resultA = mysql_query($sql) or die(mysql_error()); if(($mStatus == "mod" || $mStatus == "Diamond") && $AcademyLevel > 4){ if (mysql_num_rows($resultA) > 0) { echo "<BR><TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center><a href='lab_home.php'>Use Your Lab!</a></center></td></table><BR><table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association? <BR><BR><a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table>"; } else echo "<table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association?<BR><BR> <a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table><BR><BR> <TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center>You must be Academy level 5 to access the Lab.</center></td></table>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856000 Share on other sites More sharing options...
sanfly Posted June 15, 2009 Share Posted June 15, 2009 Actually, I think it is the { after the else that is missing: else{ echo "<table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856011 Share on other sites More sharing options...
sanfly Posted June 15, 2009 Share Posted June 15, 2009 and another } at the end, I see thats a nested if/else statement Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856012 Share on other sites More sharing options...
kendallkamikaze Posted June 15, 2009 Author Share Posted June 15, 2009 added it but its still not showing the else statement <?php $AcademyLevel = $r['AcademyLevel']; $mStatus = $r['Status']; $AcademyLevel = $r['AcademyLevel']; //echo "MS: ".$mStatus; $sql = "SELECT * FROM player WHERE id='$id'"; $resultA = mysql_query($sql) or die(mysql_error()); if(($mStatus == "mod" || $mStatus == "Diamond") && $AcademyLevel > 4){ if (mysql_num_rows($resultA) > 0) { echo "<BR><TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center><a href='lab_home.php'>Use Your Lab!</a></center></td></table><BR><table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association? <BR><BR><a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table>"; } else { echo "<table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association?<BR><BR> <a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table><BR><BR> <TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center>You must be Academy level 5 to access the Lab.</center></td></table>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856014 Share on other sites More sharing options...
sanfly Posted June 15, 2009 Share Posted June 15, 2009 Okay, lets pull this apart line by line then <?php $AcademyLevel = $r['AcademyLevel']; $mStatus = $r['Status']; $AcademyLevel = $r['AcademyLevel']; //echo "MS: ".$mStatus; $sql = "SELECT * FROM player WHERE id='$id'"; $resultA = mysql_query($sql) or die(mysql_error()); if(($mStatus == "mod" || $mStatus == "Diamond") && $AcademyLevel > 4){ $numRows = mysql_num_rows($resultA); echo "Number of rows is: $numRows<br><br>"; } ?> What is the result? Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856015 Share on other sites More sharing options...
sanfly Posted June 15, 2009 Share Posted June 15, 2009 Actually on second thoughts, this is better <?php $AcademyLevel = $r['AcademyLevel']; $mStatus = $r['Status']; $AcademyLevel = $r['AcademyLevel']; //echo "MS: ".$mStatus; $sql = "SELECT * FROM player WHERE id='$id'"; $resultA = mysql_query($sql) or die(mysql_error()); if(($mStatus == "mod" || $mStatus == "Diamond") && $AcademyLevel > 4){ $numRows = mysql_num_rows($resultA); echo "Number of rows is: $numRows<br><br>"; } else{ echo "Eeeeek! No result!<br><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856016 Share on other sites More sharing options...
kendallkamikaze Posted June 15, 2009 Author Share Posted June 15, 2009 im still new to this...so the num rows is becially taking it from player where id = id all it needs to do is go into player where id=id and then pull from the status in the player table to check if status is diamond or mod Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856017 Share on other sites More sharing options...
Ken2k7 Posted June 15, 2009 Share Posted June 15, 2009 <?php $AcademyLevel = $r['AcademyLevel']; $mStatus = $r['Status']; $AcademyLevel = $r['AcademyLevel']; //echo "MS: ".$mStatus; $sql = "SELECT * FROM player WHERE id='$id'"; $resultA = mysql_query($sql) or die(mysql_error()); if(($mStatus == "mod" || $mStatus == "Diamond") && $AcademyLevel > 4){ if (mysql_num_rows($resultA) > 0) { echo "<BR><TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center><a href='lab_home.php'>Use Your Lab!</a></center></td></table><BR><table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association? <BR><BR><a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table>"; } } else { echo "<table class=table CELLSPACING='2' CELLPADDING='2' border='0'><tr> <td class='tablegreen'> Association Adoption</td></tr> <tr><td class=tabletd width='390'><center><BR><font size='2px'>Don't have an association?<BR><BR> <a href='assoc_adoption.php'>Click here to Adopt one!</a></center><BR><BR></font></td></tr></table><BR><BR> <TABLE WIDTH='400' class='table' CELLSPACING='2' CELLPADDING='2' border='0'><tr><td class=tablegreen> The Scientific Center</td></tr><tr> <td class='tabletd' width='250'><center>You must be Academy level 5 to access the Lab.</center></td></table>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856018 Share on other sites More sharing options...
kendallkamikaze Posted June 15, 2009 Author Share Posted June 15, 2009 you got it! thanks so much!! <3 Quote Link to comment https://forums.phpfreaks.com/topic/162203-solved-else-echo-not-working-right/#findComment-856023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.