Hi,
if your database doesn't support UNION you could move the logic for that to the php code. That shouldn't bee too expensive because you have only four fields to analyse.
Do something like
SELECT id,name,CC1,CC2,CC3,CC4 FROM tablename WHERE ...
In the php code you could then walk through the result set with e.g. mysql_fetch_row and do all the stuff in php, e.g. build an array.
Example for one row fetched by mysql_fetch_row() assuming that the variable containing the row array has the name $row:
function buildArray($row,$field) {
return array('id' => $row['id'], 'name' => $row['name'], 'CC' => $row[$field]);
}
...
...
$resArray = "";
while ($row = mysql_fetch_row($result) {
if ($row['CC1']) {
$resArray[] = buildArray($row,"CC1");
if ($row['CC2']) {
$resArray[] = buildArray($row,"CC2");
if ($row['CC3']) {
$resArray[] = buildArray($row,"CC3");
if ($row['CC4']) {
$resArray[] = buildArray($row,"CC4");
}
}
}
}
}
It's probably not the best way and coding style, just an example (a multi dimensional $resArray might be better because id and name are redundant in the example above) 🙂
I couldn't test the code above so there might be syntax or logical errors 🙁
You should then have an array that contains the data like shown in your result table.
Regards,
Thomas