advancedfuture Posted June 21, 2008 Share Posted June 21, 2008 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 More sharing options...
DanielWhite Posted June 21, 2008 Share Posted June 21, 2008 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 https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-570885 Share on other sites More sharing options...
advancedfuture Posted June 21, 2008 Author Share Posted June 21, 2008 newp :\ I've been trying several things no results :\ Link to comment https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-570890 Share on other sites More sharing options...
advancedfuture Posted June 21, 2008 Author Share Posted June 21, 2008 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.... Link to comment https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-570896 Share on other sites More sharing options...
dannyb785 Posted June 21, 2008 Share Posted June 21, 2008 If the code you have really doesnt work... well php can be finicky(I've noticed on occasion) so I'd say switch the clauses to be like "if (num_rows > 0) echo view; else echo generate. I don't see any other reason why the code doesn't work. Link to comment https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-571130 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 @dannyb785: He already solved it. Link to comment https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-571132 Share on other sites More sharing options...
dannyb785 Posted June 21, 2008 Share Posted June 21, 2008 @dannyb785: He already solved it. my bad. the "problem solved" option wasn't check for the thread. How did you know it was solved? Link to comment https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-571134 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 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 https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-571136 Share on other sites More sharing options...
dannyb785 Posted June 22, 2008 Share Posted June 22, 2008 ^ lol. whats funny about that is that I assumed that his reply(that said problem solved) was the guy who first suggested help but was saying "I need to wake up, my bad". Link to comment https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-571322 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Share Posted June 22, 2008 <?php $queryDelete = "SELECT * FROM invoices WHERE clientId = '".$clientId".'"; ?> your var $clientid won't pass if it's in your code as a string Link to comment https://forums.phpfreaks.com/topic/111228-help-with-if-else-statement/#findComment-571336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.