Jump to content

If Else delima returns nothing in the Else


TecTao

Recommended Posts

I'm getting frusted over an if else statememt that won't work.  It is calling one variable from the table.  If the variable is in the table it will display one thing, if the variable is absent, it should display something else.  I've tried !empty, isset, even $num_rows =1, but the content in the else doesn't display.  Here's the code:

 


<?
$result = mysql_query( "SELECT * FROM codeWords WHERE Mycode = '$MyCode' " )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
  while ($row = mysql_fetch_array($result))
  {
     extract($row);
     
if (!empty( $MyCode  )) {    
echo "here is the code word";
} else {
echo "you need to go back and get the code";
}
$row_count++; 
}
mysql_close;
?>

 

When the code variable is correct the "here is the code word" displays.  when the code variable is incorrect, what should appear as "you need to go back and get the code" is just blank.

 

Any thoughts on how to structure the query in such a way that eh incorrect text appears?

 

Thanks,

 

 

consider the possibilities of this

$result = mysql_query( "SELECT * FROM codeWords WHERE Mycode = '$MyCode' " )
or die("SELECT Error: ".mysql_error());

1. error = code stops

2. no results = never enters while loop

3. 1 or more results = enter while loop = 2 possibilities depending upon value of original $MyCode in the query

      a) either ALL sets contain a value for MyCode; or

      b) ALL sets contain no value for MyCode

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.