Jump to content

Counting specified fields that are not NULL


mourningreign

Recommended Posts

I'd like to count 4 specified text fields (last,last2,last3,last4) for which contain data and sum the total
then 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.
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);
?>
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

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.