Jump to content

[SOLVED] Adding a while $var


UrbanTwitch

Recommended Posts

Hi, I'm trying to add what the $total_overall_cookies variable would be. Here is an image to better explain myself.

 

kc1d8n.jpg

 

I want to add the Total Cookies on the right and present it somewhere near the bottom.

 

The $totalcookies variable is displayed inside the while loop

 

full page php: http://www.rmb.pastebin.com/d28d8111b

 

is there any way to add the $total_cookie variable in every while loop made?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/168974-solved-adding-a-while-var/
Share on other sites

i don't quite understand your question, but try

$total = 0;
while ($list = mysql_fetch_array($result)) {
if($ref_mem['ref_valid'] == 'yes') { $acookie = "10"; }else{ $acookie = "0"; }
if($ref_mem['ref_login'] == 'yes') { $bcookie = "5"; }else{ $bcookie = "0"; }
if($ref_mem['ref_topic'] == 'yes') { $ccookie = "10"; }else{ $ccookie = "0"; }
if($ref_mem['ref_ncomment'] == 'yes') { $dcookie = "5"; }else{ $dcookie = "0"; }
if($ref_mem['ref_profile'] == 'yes') { $ecookie = "5"; }else{ $ecookie = "0"; }
if($ref_mem['ref_avatar'] == 'yes') { $fcookie = "5"; }else{ $fcookie = "0"; }
if($ref_mem['ref_tencookies'] == 'yes') { $gcookie = "10"; }else{ $gcookie = "0"; }
if($ref_mem['ref_ref'] == 'yes') { $hcookie = "20"; }else{ $hcookie = "0"; }
  
  
$total_cookies = $acookie+$bcookie+$ccookie+$dcookie+$ecookie+$fcookie+$gcookie+$hcookie+10;
$total += total_cookies; 
... 

 

 

I would so something like this:

<?php

$cookie_values = array(
'ref_valid'      => 10
'ref_login'      => 5
'ref_topic'      => 10
'ref_ncomment'   => 5
'ref_profile'    => 5
'ref_avatar'     => 5
'ref_tencookies' => 10
'ref_ref'        => 20
);

$cookies = array();
$total = 0;

while ($list = mysql_fetch_array($result)) 
{
$get_teh_datawee = mysql_query("SELECT * FROM `members` WHERE `id` = '$list[referral_id]'");
$ref_mem = mysql_fetch_array($get_teh_datawee);

foreach ($ref_mem as $key => $value)
{
	if ($value == "yes")
	{
		$cookies[$key] = $cookie_values[$key];
		$total += $cookie_values[$key];
	}
	else
	{
		$cookies[$key] = 0;
	}
}
}

print_r($cookies);

 

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.