Jump to content

Recommended Posts

I just testing something like what is going on here.

 

When you don't use an alias for the sum() term and the WHERE clause is false, there won't be any rows in the result set. mysql_num_rows would == 0.

 

When you do use an alias for the sum() term and the WHERE clause is false, you get one row in the result set and the value for the fetched alias field is a null.

i mean is there a reason why this works and the other way doesnt? i was reading about mysql_num_rows returning always as 1 when used as a sum. so if i only have 1 entry in the db for cycle oil "witch i prob always will becuase i buy it in bulk at the begining of the year and that ususally lasts me all season" then for the other quarters there shouldnt be anything, except on the annual report.

yeah pfmabismad thats what i just was saying something about lol, sorry u responded while i was responding =) did i just noob jessicas code up when i put it in there, or did she make a mistake with it? because what she wrote is way over my comprehension level lol.

thats why its working the way i have it, but its soo not efficiant. i have it set to check without a sum, if theres anything there, then add the sum all up, if theres nothing there then print 0.00 the concept is good i guess becuase it works, but the procedure is just a mess lol

This code works, but wow, its ridiclious


<!-- Q1 CYCLE OIL BREAKDOWN -->    
   <td width="25%" valign="top"><font face="verdana" size="1"><b>Q1 Cycle Oil</b><br />$
<?php
$q1_cycle_oil_check = "SELECT * FROM expense_fuel WHERE fuel_code = 017 AND year = $exp_year AND month between 01 and 03";
$q1_cycle_oil_check_results = mysql_query($q1_cycle_oil_check) or die(mysql_error());
$q1_cycle_oil_check_count = mysql_num_rows($q1_cycle_oil_check_results);
if ($q1_cycle_oil_check_count > 0)

{

$q1_cycle_oil = "SELECT SUM(amount) AS q1_cycle_oil_exp FROM expense_fuel WHERE fuel_code = 017 AND year = $exp_year AND month between 01 and 03";
$q1_cycle_oil_results = mysql_query($q1_cycle_oil) or die(mysql_error());
while($row = mysql_fetch_array($q1_cycle_oil_results))
{ 
echo $row['q1_cycle_oil_exp']; 
} 
} else { echo "0.00"; }
?>
</font></td>
<!-- / END / Q1 CYCLE OIL BREAKDOWN -->       

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.