jaxdevil Posted January 17, 2008 Share Posted January 17, 2008 Below is my code snippet. This is for an invoice/receipt system. The page is called with post data that has the variable $di (customer id) and $auctiondate (the date of the auction) I need the page to look for the amounts in total, payments, etc and then it performs calculations to determine what is due, what we owe the customer, or what they owe us, etc. This all works great, except for when a customers record is called up and he did not pay any deposit or any previous payments (normally they pay a deposit so there is SOME value for the math calculations to work with) so the math calculations do not have anything to go by, they then do not display anything (not even 0.00 in the fields) so it breaks the whole page and the normal html layout becomes all screwy looking. Here is my code, I am assuming there is a procedure to define a $variable as 0.00 if there is nothing displayed in the row? check out the code below and let me know.. <?php $sql = "SELECT * FROM checkout WHERE bidnum=$di AND paid='no' AND deposit_storage='0'"; $query = mysql_query($sql); $sum = array(); $sum2 = array(); $sum3 = array(); $sum4 = array(); while($row = mysql_fetch_array($query)) { $sum[] = (0+$row['amt']+0); $sum2[] = (0+$row['amt']+0); $sum3[] = (0+$row['amt']+0); $sum4[] = (0+$row['amt']+0); $ref = (0+$row['ref']+0); $checkout = (0+$row['checkout']+0); $type = $row['type']; $amt = (0+$row['amt']+0); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/ Share on other sites More sharing options...
revraz Posted January 17, 2008 Share Posted January 17, 2008 $query = mysql_query($sql); if (mysql_num_rows($query)==0) { $something = 0; } Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/#findComment-442141 Share on other sites More sharing options...
jaxdevil Posted January 17, 2008 Author Share Posted January 17, 2008 I am trying this but its not changing anything. Any ideas? is there something wrong with my else statement? if (mysql_num_rows($query)==0) { $sum = 0.00; $sum2 = 0.00; $sum3 = 0.00; $sum4 = 0.00; } else { $sum = array(); $sum2 = array(); $sum3 = array(); $sum4 = array(); } Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/#findComment-442152 Share on other sites More sharing options...
revraz Posted January 17, 2008 Share Posted January 17, 2008 Could that mean you have rows that do match the expression but the values are empty? Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/#findComment-442158 Share on other sites More sharing options...
jaxdevil Posted January 17, 2008 Author Share Posted January 17, 2008 Yes, exactly. So it is pulling up rows, my bad. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/#findComment-442176 Share on other sites More sharing options...
revraz Posted January 17, 2008 Share Posted January 17, 2008 Check the $sum's instead. If there are only 4, you can just do a if statement for each one. Or you can do a FOR loop. Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/#findComment-442179 Share on other sites More sharing options...
jaxdevil Posted January 17, 2008 Author Share Posted January 17, 2008 I got it, here is a code snippet I used in another part of the script (I have a few places where I needed that) if (mysql_num_rows($query)==0) { $deposit_amt = 0.00; $checkout2 = 0.00; $sum12 = 0.00; } else { while($row = mysql_fetch_array($query)) { $deposit_amt = $row['deposit_amt']; $checkout2 = $row['checkout']; } } Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/#findComment-442180 Share on other sites More sharing options...
revraz Posted January 17, 2008 Share Posted January 17, 2008 In your DB, just make the Default 0.00, so if nothing is entered, it will still have that value when you pull it. Quote Link to comment https://forums.phpfreaks.com/topic/86536-solved-if-no-rows-match-expression-make-something000/#findComment-442181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.