Angeleyezz Posted October 6, 2012 Author Share Posted October 6, 2012 lol i know im a complete noob Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383299 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2012 Share Posted October 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383301 Share on other sites More sharing options...
Angeleyezz Posted October 6, 2012 Author Share Posted October 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383302 Share on other sites More sharing options...
Angeleyezz Posted October 6, 2012 Author Share Posted October 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383303 Share on other sites More sharing options...
Angeleyezz Posted October 6, 2012 Author Share Posted October 6, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383304 Share on other sites More sharing options...
Angeleyezz Posted October 6, 2012 Author Share Posted October 6, 2012 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 --> Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383305 Share on other sites More sharing options...
darkfreaks Posted October 6, 2012 Share Posted October 6, 2012 using empty() will check for 0.00 [float] if( $variable <1 && empty($variable)) { echo '0.00'; } Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383306 Share on other sites More sharing options...
Angeleyezz Posted October 6, 2012 Author Share Posted October 6, 2012 it wont be empty using SUM AS $variable though, it will return as 1 reguardless if data is there or not, isnt that why im having this problem dark? or am i missing something completely different now lol Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383307 Share on other sites More sharing options...
darkfreaks Posted October 6, 2012 Share Posted October 6, 2012 (edited) SQL SUM returns NULL on empty. empty() checks for 0.00, 0, NULL, ' ' and blank arrays Edited October 6, 2012 by darkfreaks Quote Link to comment https://forums.phpfreaks.com/topic/269170-mysql_num_rows-not-displaying-properly/page/2/#findComment-1383309 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.