RE: Aggregate MySQL functions in html table via php - having problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Jos,

Sorry the code snip wasn't clearer - you'll notice the line with the
Avg(RawData) as Mn... has been left out (ie, I just asked for RawData)
and the aggregate function in the printf statement still fails.

If the query statement includes select RawData as well as the Mn and
Std, and I then use the print_r($myrow), I see values for RawData along
with Mn and SD so it appears that I am getting a handle on the RawData
values I want to use to create the aggregate values in the printf
statement. Again, I have left out the Mn and Std values and ONLY
requested the RawData column and the printf...$myrow['avg(RawData)'],
$myrow['std(RawData)']... returns an error (listed below)

What am I not seeing here?

Thanks for your reply.

Doug

-----Original Message-----
From: Juffermans, Jos [mailto:jjuffermans@xxxxxxxxxxxxxxx] 
Sent: Monday, May 02, 2005 10:10 AM
To: php-db@xxxxxxxxxxxxx
Subject: RE:  Aggregate MySQL functions in html table via php -
having problems

Hi,

Since you're telling mysql "Avg(RawData) as Mn" the index in $myrow
won't be "Avg(RawData)", it'll just be "Mn".

Try printing the entire $myrow to find out what you're receiving from
mysql:
	print "<pre>"; print_r($myrow); print "</pre>"; That will show
you the keys that you should use.

Jos


-----Original Message-----
From: Finner, Doug [mailto:Dfinner@xxxxxxxxxxxx]
Sent: 02 May 2005 16:05
To: php-db@xxxxxxxxxxxxx
Subject:  Aggregate MySQL functions in html table via php -
having problems


I want to build a table that is populated from a MySQL query and have
the table include some aggregate data (mean, sd, and cv).
 
If I select 'avg(RawData) as Mn' - and then stuff Mn into the table -
life is good.
If I try and select just RawData and computed the mean and sd at the
time the table is created, I get an error 'Unidentified index:
avg(RawData) in <php file name> at line <where I try and do the avg and
sd>
 
The format used below that does not work came from a suggestion by Oli
(the original suggestion used echo rather than printf, but it seems to
me the concept should be identical - am I wrong here???).
 
I have a working method so I am in good shape, I'm just trying to learn
other ways to get the same result.  Any tips or pointers are
appreciated.
 
Doug
 
/////////////// Query for STATISTICAL data
///////////////////////////////// 

$sql = "SELECT RunID, ItemSN, RawDataDesc, ReasonRun, RawData,  //note,
I've tried with including and excluding RawData from this query - no
change in the error
Avg(RawData) as Mn, Std(RawData) as SD,                 //note, I've
tried leaving this line in and taking it out - no change in the error.
(Std(RawData)/Avg(RawData) * 100) as CV
FROM $table
Where RawData != 'Passed' and RawData != 'Failed'
Group By RawDataDesc";
 
echo "<br><br>";
 
$result = mysql_query($sql, $link)
or die(mysql_error());
 
echo "This is the statistical data report for Item: $table <br><br>";
echo "<table border=1>\n"; echo
"<tr><td>RunID</td><td>ItemSN</td><td>RunReason</td><td>Desc</td>
<td BGCOLOR='33FF99'>Mean</td><td BGCOLOR='99FFCC'>SD</td><td
BGCOLOR='FFCC66'>CV</tr>\n";
 
while($myrow = mysql_fetch_assoc($result)) {
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
<td BGCOLOR='33FF99'>%.1f</td><td BGCOLOR='99FFCC'>%.2f</td><td
BGCOLOR='FFCC66'>%.2f</tr>\n", $myrow['RunID'], $myrow['ItemSN'],
$myrow['ReasonRun'], $myrow['RawDataDesc'], $myrow['Mn'], $myrow['SD'],
$myrow['CV']); // this works fine every time
//$myrow['avg(RawData)'], $myrow['std(RawData)'], $myrow['CV']);
//this was suggested by someone on this list but returns Unidentified
index: avg(RawData)in <php file name> at line <this line when
uncommented and used }
 
echo "</table>\n";
_______________________________________________________________________
This e-mail message has been sent by Kollsman, Inc. and is for the use
of the intended recipients only. The message may contain privileged
or confidential information. If you are not the intended recipient
you are hereby notified that any use, distribution or copying of
this communication is strictly prohibited, and you are requested to
delete the e-mail and any attachments and notify the sender immediately.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux