Jump to content

Help with If / Else Statement


advancedfuture

Recommended Posts

What I am trying to do here is check the database to see if the client invoice exists prior to showing the "generate invoice" button. And if it does exist I want it to show the "view invoice" button.

 

However even though the invoice does exist it never hits the else statement! It just keeps showing the "generate invoice" button.

 

Any help would be appreciated! I'm sure its simple..

 

//check to see if invoice is already generated before echoing the generate
//invoice button!

$queryDelete = "SELECT * FROM invoices WHERE clientId = '$clientId'";
$resultsDelete = mysql_query($queryDelete) or die("error");
if(mysql_num_rows($resultsDelete) <= 0)
{
    echo '<input type="submit" name="generateInvoice" value="Generate Invoice" />';
}

//If Invoice Exists Show Invoice
else
{
   echo '<input type="submit" name="viewInvoice" value="View Invoice" />';
}

Link to comment
https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/
Share on other sites

Try changing this:

 

if(mysql_num_rows($resultsDelete) <= 0)
{
    echo '<input type="submit" name="generateInvoice" value="Generate Invoice" />';
}

//If Invoice Exists Show Invoice
else
{
   echo '<input type="submit" name="viewInvoice" value="View Invoice" />';
}

 

To this:

if(mysql_num_rows($resultsDelete) == 0)
{
    echo '<input type="submit" name="generateInvoice" value="Generate Invoice" />';
}

//If Invoice Exists Show Invoice
else if(mysql_num_rows($resultsDelete) == 1)
{
   echo '<input type="submit" name="viewInvoice" value="View Invoice" />';
}

wow i feel like an idiot. Then again I havnet slept since yesterday. haha

 

I was trying to pass $clientId in my sql query but I hadn't even defined the variable yet so it was blank.

 

hahaha. I think I need a Rockstar to wake me up....

my bad. the "problem solved" option wasn't check for the thread. How did you know it was solved?

 

I'm pretty sure he said it right before your post.

wow i feel like an idiot. Then again I havnet slept since yesterday. haha

 

I was trying to pass $clientId in my sql query but I hadn't even defined the variable yet so it was blank.

hahaha. I think I need a Rockstar to wake me up....

 

=P

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.