Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Etherguy
Forum Commoner
Posts: 70 Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York
Post
by Etherguy » Wed May 26, 2004 8:15 am
I am trying to output mysql results into a multidimensional array so I can do some charting with it. I can't seem to get the data in the format I need. Which is :
Code: Select all
<?php
$chart[ 'chart_data' ] = array ( array ( "", "Dan", "Gary", "Tom", "Al", "Pete" ), array ( "", 63, 40, 10, 1, 0 ) );
?>
Basically I have 2 fields... a name field and a numeric field. If I manually do the MD-Array it works like a champ. If I try to use data from mysql is dies or loops forever.
I have tried imploding the data, which works fine when I am not trying to create a MD-Array.
Any ideas?
Etherguy
Forum Commoner
Posts: 70 Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York
Post
by Etherguy » Wed May 26, 2004 8:38 am
Here is what I have
Code: Select all
<?php
$result1=MYSQL_QUERY("SELECT DISTINCT Username,sum(AcctSessionTime)/60 as SesTime From radacct where Username != '' group by Username");
while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$usr[] = $line[Username];
$ses[] = $line[SesTime];
}
$chart[ 'chart_data' ] = array (array("",$usr) ,array( "",$ses)) ;
?>
The result is a never ending loop.
Let me know if there is anything else I can provide.
Etherguy
Forum Commoner
Posts: 70 Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York
Post
by Etherguy » Wed May 26, 2004 11:37 am
nothing on this.. huh...
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Wed May 26, 2004 11:44 am
change this:
Code: Select all
<?php
while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$usr[] = $line[Username];
$ses[] = $line[SesTime];
}
?>
to this:
Code: Select all
<?php
while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$usr[] = $line['Username'];
$ses[] = $line['SesTime'];
}
?>
Etherguy
Forum Commoner
Posts: 70 Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York
Post
by Etherguy » Wed May 26, 2004 12:00 pm
No go on that. Made no difference.. after the loop finally ends.. I see in my graph a title of Array... which tells me that it is not seeing the data, but rather the array it self. As I stated before I have tried imploding the array, and the data looks ok when echoed... but does not work when I try to make a multidimensional array out of it.
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Wed May 26, 2004 12:09 pm
try:
Code: Select all
<?php
while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
print_r($line);
}
?>
and see what that shows. Also try print_r($chart) once you fill it and check to see that its properly filled.
Etherguy
Forum Commoner
Posts: 70 Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York
Post
by Etherguy » Wed May 26, 2004 1:25 pm
The
worked like a champ. I was able to see what I was missing in my array that was causing the looping issue.
Thank you for your time.
Etherguy
Forum Commoner
Posts: 70 Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York
Post
by Etherguy » Wed May 26, 2004 1:32 pm
More then just a friend... more like a favorite uncle or something.
I am sure if php.net kept stats on visiting IP addresses mine would rank up there
Thanks again for the help!