Jump to content

[SOLVED] if no rows match expression, make $something=0.00


jaxdevil

Recommended Posts

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);
}
?>

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();
}

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'];
}
}

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.