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,

 

 

Link to comment
Share on other sites

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

 

 

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.