Jump to content

[SOLVED] else echo not working right.


kendallkamikaze

Recommended Posts

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>";
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

}

?>

Link to comment
Share on other sites

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>";
}
}

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>";
}

?>

Link to comment
Share on other sites

<?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>";
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.