mourningreign Posted November 22, 2006 Share Posted November 22, 2006 I'd like to count 4 specified text fields (last,last2,last3,last4) for which contain data and sum the totalthen count 4 more text fields (last5,last6,last7,last8) for which contain data and sum that total.Each total which will be a number from 2-4 will have a dollar value in a related table that I can then sum and display on a page. Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/ Share on other sites More sharing options...
joshi_v Posted November 22, 2006 Share Posted November 22, 2006 select sum(field1,field2,field3,field4) as First_count, sum(field5,field6,field7,field8) as second_count from table_name;For dollor sybmol you have to append it seperately. Is this what you are looking for?Regards,Joshi. Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128438 Share on other sites More sharing options...
mourningreign Posted November 22, 2006 Author Share Posted November 22, 2006 I'll be happy to just deal with one at a time...I get a syntax error. Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128443 Share on other sites More sharing options...
Jenk Posted November 22, 2006 Share Posted November 22, 2006 [code]SELECT CONCAT('$', SUM(`col1`, `col2`, `col3`, `col4`)) AS `count1` --etc[/code] Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128445 Share on other sites More sharing options...
mourningreign Posted November 22, 2006 Author Share Posted November 22, 2006 SELECT CONCAT('$', SUM(`last`, `last2`, `last3`, `last`)) AS `count1`Syntax error still Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128448 Share on other sites More sharing options...
joshi_v Posted November 22, 2006 Share Posted November 22, 2006 post the query with error message here! Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128450 Share on other sites More sharing options...
mourningreign Posted November 22, 2006 Author Share Posted November 22, 2006 Did I screw it all up?<?php$last_Recordset1 = "1";if (isset(1)) { $last_Recordset1 = (get_magic_quotes_gpc()) ? 1 : addslashes(1);}$last2_Recordset1 = "1";if (isset(2)) { $last2_Recordset1 = (get_magic_quotes_gpc()) ? 2 : addslashes(2);}$last3_Recordset1 = "1";if (isset(3)) { $last3_Recordset1 = (get_magic_quotes_gpc()) ? 3 : addslashes(3);}$last4_Recordset1 = "1";if (isset(4)) { $last4_Recordset1 = (get_magic_quotes_gpc()) ? 4 : addslashes(4);}mysql_select_db($database_bbb, $bbb);$query_Recordset1 = sprintf("SELECT CONCAT('$', SUM(`%s`, `%s`, `%s`, `%s`)) AS `count1`", $last_Recordset1,$last2_Recordset1,$last3_Recordset1,$last4_Recordset1);$Recordset1 = mysql_query($query_Recordset1, $bbb) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?> Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128451 Share on other sites More sharing options...
joshi_v Posted November 22, 2006 Share Posted November 22, 2006 Replace your query with this query[code]<?php$query_Recordset1 = "SELECT CONCAT('$',SUM('$last_Recordset1','$last2_Recordset1','$last3_Recordset1','$last4_Recordset1')) AS `count1` ";?>[/code] Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128453 Share on other sites More sharing options...
mourningreign Posted November 22, 2006 Author Share Posted November 22, 2006 This-[CODE]<?php$last_Recordset1 = "1";if (isset(1)) { $last_Recordset1 = (get_magic_quotes_gpc()) ? 1 : addslashes(1);}$last2_Recordset1 = "1";if (isset(2)) { $last2_Recordset1 = (get_magic_quotes_gpc()) ? 2 : addslashes(2);}$last3_Recordset1 = "1";if (isset(3)) { $last3_Recordset1 = (get_magic_quotes_gpc()) ? 3 : addslashes(3);}$last4_Recordset1 = "1";if (isset(4)) { $last4_Recordset1 = (get_magic_quotes_gpc()) ? 4 : addslashes(4);}mysql_select_db($database_bbb, $bbb);$query_Recordset1 = "SELECT CONCAT('$',SUM('$last_Recordset1','$last2_Recordset1','$last3_Recordset1','$last4_Recordset1')) AS `count1` ";$last_Recordset1,$last2_Recordset1,$last3_Recordset1,$last4_Recordset1);$Recordset1 = mysql_query($query_Recordset1, $bbb) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?>[/code]Gets this -Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /homepages/19/d125543458/htdocs/bbb/test.php on line 4 Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128463 Share on other sites More sharing options...
joshi_v Posted November 22, 2006 Share Posted November 22, 2006 Just remove the above part of the query.I think that part is automatically generated by Dreamweaver.Use just query part.nothing elseand let us know the status. Link to comment https://forums.phpfreaks.com/topic/28073-counting-specified-fields-that-are-not-null/#findComment-128483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.