Page 2 of 2
Re: count and give a total of a specific output
Posted: Fri Oct 23, 2015 3:40 am
by jonnyfortis
Celauran wrote:$options is an array and will always evaluate to true, so you've created an infinite loop. What I suspect you want is closer to this:
Code: Select all
mysql_select_db($database_hostprop, $hostprop);
$query_rsPayment = "SELECT * FROM host_payments2014, plus_signupComplete, host_editprop2015, hostStudentProperties WHERE plus_signupComplete.studentID = host_payments2014.id AND plus_signupComplete.studentID = host_payments2014.id AND host_editprop2015.prop_id = plus_signupComplete.prop_id AND host_payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND host_payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND hostStudentProperties.propID = plus_signupComplete.propFull ORDER BY host_payments2014.payment_id DESC";
$rsPayment = mysql_query($query_rsPayment, $hostprop) or die(mysql_error());
$totalRows_rsPayment = mysql_num_rows($rsPayment);
$options = array(
'Option 1: Balance Before' => 0,
'Option 2: Balance Before' => 0,
'Option 3: Balance Before' => 0,
'Option 4: Final Payment' => 0,
);
while ($row_rsPayment = mysql_fetch_assoc($rsPayment)) {
if (array_key_exists($row_rsPayment['payment_type'], $options)) {
$options[$row_rsPayment['payment_type']]++;
}
}
print_r($options);
i have tried to extract the array into usable seperate variables
Code: Select all
extract($options);
echo $balances = explode (" ", $options);
echo $balances[0];
echo $balances[1];
echo $balances[2];
echo $balances[3];
but this is not giving me an output
Re: count and give a total of a specific output
Posted: Fri Oct 23, 2015 6:17 am
by Celauran
Not really sure what you're trying to do. You've already got an array of keys and values. What are you trying to accomplish?
Re: count and give a total of a specific output
Posted: Fri Oct 23, 2015 6:43 am
by jonnyfortis
Celauran wrote:Not really sure what you're trying to do. You've already got an array of keys and values. What are you trying to accomplish?
i want to be able to use the figures that are outputted in the array separately. i want to turn each of the results into a variable that i can use in different equations for example
these are my results
Array ( [Option 1: Balance Before] => 19 [Option 2: Balance Before] => 34 [Option 3: Balance Before] => 15 [Option 4: Final Payment] => 9 )
i want to be able to multiple them 19+34+15 =
o just have the numbers and seperate variables
Re: count and give a total of a specific output
Posted: Fri Oct 23, 2015 7:26 am
by jonnyfortis
jonnyfortis wrote:Celauran wrote:Not really sure what you're trying to do. You've already got an array of keys and values. What are you trying to accomplish?
i want to be able to use the figures that are outputted in the array separately. i want to turn each of the results into a variable that i can use in different equations for example
these are my results
Array ( [Option 1: Balance Before] => 19 [Option 2: Balance Before] => 34 [Option 3: Balance Before] => 15 [Option 4: Final Payment] => 9 )
i want to be able to multiple them 19+34+15 =
o just have the numbers and seperate variables
sorted it thanks
$i = 0;
foreach ($options as $key => $value){
$variable[$i] = "$value";
$i++;
}
$balanceTotal = $variable[0] + $variable[1] + $variable[2] + $variable[3];
Re: count and give a total of a specific output
Posted: Fri Oct 23, 2015 7:30 am
by Celauran