Link to home
Start Free TrialLog in
Avatar of tjyoung
tjyoung

asked on

How to assign a different variable name to each loop?

Hi, below I have a query that when ran on my table produces the following correct result:
Phone 0,2,5
Text 2,4,3
Email 0,3,2

The series of 3 numbers represent how many of each type of call for the past 3 months.

Problem is, I can't for the life of me figure out how I can get unique variable names for the 3 series of numbers kind of like:

$name_array1 = $row["array"];

then next loop
$name_array2 = $row["array"];

and last loop
$name_array3 = $row["array"];

I need to be able to display the results in different areas of the page so I need to be able to echo out each one by itself. Make any sense??

$result = mysql_query("SELECT t.name, ifnull(c.array,'0, 0, 0') array from calltypes t left outer join (SELECT CallType, concat(sum(if(CallDate>='$threemonthsago' and CallDate<'$twomonthsago',1,0 and account_id = '$account_id')),', ', sum(if(CallDate>='$twomonthsago' and CallDate<'$onemonthago',1,0 and account_id = '$account_id')),', ', sum(if(CallDate>='$onemonthago' and CallDate<'$currentmonth',1,0 and account_id = '$account_id'))) array FROM callers WHERE CallDate >= '$threemonthsago' AND CallDate < '$currentmonth' GROUP BY CallType order by CallType) c on (t.id=c.CallType)");

while($row = mysql_fetch_array($result)){
$name = $row["name"];
$name_array = $row["array"];
echo $name." ".$name_array."<br />";
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjyoung
tjyoung

ASKER

Thank God... works perfect.
Much appreciated! Never would have figured that out.