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

Link to comment
Share on other sites

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

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.