Am trying to write a query, seems simple enough
SELECT SUM(members.Under_15_Vic) + SUM(members.Under_12_Vic) + SUM(members.Under_18_Vic)
FROM members
All I want to do is get a total of the 3 columns, it works providing all the columns have a value.
If a column has no values entered (all entries are null) then the SUM ceases to work?
The columns represent payment for junior tournaments, column type is set as Numeric, tinyint
The outcome of the query is being used as part of a summary page, Is there a way I can then Insert the outcome into another table?
A simple Query?
Moderator: General Moderators
Re: A simple Query?
Why don' t you use:
it' s much faster.
Code: Select all
//short version code to get you started
$arraySumColumns[]=mysqli->query( "SELECT Under_15_Vic, Under_12_Vic, Under_18_Vic FROM members;");
$sum=array_sum($arraySumColumns);Re: A simple Query?
I guess it is obvious that I am a newbie to PHP. I use dreamweaver and have created a database, it is working fine. Have not used arrays before, spent most of the day doing online tutorials but still cannot get your code to work
Tried some simple arrays and they work
// Test 1 Output =45
$a=array(0=>"5",1=>"15",2=>"25");
echo array_sum($a);
// Test 2 Output =9.3
$value2= array(1.5,2.3,5.5);
echo array_sum($value2);
Tried your code.
$VJSinc[]=mysqli->query( "SELECT Under_15_Vic, Under_12_Vic, Under_18_Vic FROM members;");
$sum=array_sum($VJSinc);
echo array_sum($VJSinc);
And got this error message
Parse error: syntax error, unexpected T_OBJECT_OPERATOR
Thankyou for your reply any assistance would be greatly appreciated.
Tried some simple arrays and they work
// Test 1 Output =45
$a=array(0=>"5",1=>"15",2=>"25");
echo array_sum($a);
// Test 2 Output =9.3
$value2= array(1.5,2.3,5.5);
echo array_sum($value2);
Tried your code.
$VJSinc[]=mysqli->query( "SELECT Under_15_Vic, Under_12_Vic, Under_18_Vic FROM members;");
$sum=array_sum($VJSinc);
echo array_sum($VJSinc);
And got this error message
Parse error: syntax error, unexpected T_OBJECT_OPERATOR
Thankyou for your reply any assistance would be greatly appreciated.