[thelist] PHP & Crosstabs [long]

Jay Blanchard jay.blanchard at niicommunications.com
Tue May 7 13:35:06 CDT 2002


[snip]
//query for crosstab
$row_num = 0;
$qx = "SELECT RecordDate, ";
while($rowx = mysql_fetch_object($dbrid)){
	$row_num++;
		if($row_num <> mysql_num_rows($dbrid)){
		$qx .= "SUM(IF(RecordID = '$rowx->RecordID', 1, 0)) AS r$rowx->RecordID,
";
		}
		else {
		$qx .= "SUM(IF(RecordID = '$rowx->RecordID', 1, 0)) AS r$rowx->RecordID ";
		}
	}
$qx .= "FROM tblCrosstab ";
$qx .= "GROUP BY RecordDate ";
$dbx = mysql_query($qx, $dbconnect)

The query returned by the code above is;

SELECT RecordDate
SUM(IF(RecordID = '100101', 1, 0)) AS r100101,
SUM(IF(RecordID = '100118', 1, 0)) AS r100118,
SUM(IF(RecordID = '100119', 1, 0)) AS r100119,
SUM(IF(RecordID = '100120', 1, 0)) AS r100120
FROM tblCrosstab
GROUP BY RecordDate
[/snip]

I think what I need is a way to get at the names of the columns (r100101,
r100118, etc.)

Thanks!

Jay





More information about the thelist mailing list