I have a script that pulls results from several MySQL tables. What I want to do is combine two of the results into a single column heading.
The query goes something like this;
Code: Select all
SELECT dat_a_mainrequest.Number,RequestDate AS 'Request Date',requestA.CommNumber, requestB.CommNumber,RequestType AS 'Request Type',RequestStatus AS 'Status',location AS 'Office'Is this a possibility?
To further explain, I am creating the resulting columns on the fly using the following script;
Code: Select all
// Execute query which is not NULL.
for($i=1;$i<=3;$i++) {
$query="query"."$i";
if($$query == "") {
continue; // Skipping NULL queries
}
if (!($result = mysql_db_query($DB, $$query))) {
DisplayErrMsg(sprintf("internal error %d:%s
", mysql_errno(), mysql_error()));
exit() ;
}
if(($num_rows = mysql_num_rows($result))!=0) {
$searchSuccess="YES";
?>
<DIV align="center"><CENTER>
<TABLE border="0" cellpadding="3" cellspacing="2">
<TR>
<?php
// Find Nr of Fields returned and print as column titles.
while($field = mysql_fetch_field($result)) {
echo "<th nowrap bgcolor=$cfgThBgcolor>$field->name</th>";
}
echo "</tr>
";
$rcol = 0; // Alternate row colouring - Pt 1.
// Print each result row returned from the query.
while ($row = mysql_fetch_row($result)) {
$bgcolor = $cfgBgcolorOne; // Alternate row colouring - Pt 2.
$rcol % 2 ? 0: $bgcolor = $cfgBgcolorTwo; // Alternate row colouring - Pt 3.
echo "<TR bgcolor=$bgcolor>";
// Traverse along row for number of fields returned by query.
for ($k = 0; $k < mysql_num_fields($result); $k++) {
if ($k == 1) {
// Reformat date in ISO format YYYY-MM-DD to DD/MM/YYYY
if (ereg ("(ї0-9]{4})-(ї0-9]{1,2})-(ї0-9]{1,2})", $rowї1], $regs)) {
$rowї1] = "$regsї3]/$regsї2]/$regsї1]";
}
if ($rowї1] == "00/00/0000") {
$rowї1] = "n/a";
}
}
if ($k == 3) {
if (ereg ("(ї0-9]{4})-(ї0-9]{1,2})-(ї0-9]{1,2})", $rowї3], $regs)) {
$rowї3] = "$regsї3]/$regsї2]/$regsї1]";
}
}
if ($k == 6) {
if (ereg ("(ї0-9]{4})-(ї0-9]{1,2})-(ї0-9]{1,2})", $rowї6], $regs)) {
$rowї6] = "$regsї3]/$regsї2]/$regsї1]";
}
}
if ($k == 0) {
printf (" <td nowrap><a href="viewdata.php4?bcinum=" . $rowї0] . "">$rowї0]<a/></td> ");
}else{
printf (" <td nowrap> %s </td>
", htmlspecialchars ($rowї$k]));
}
}
echo "</TR>";
$rcol++; // Alternate row colouring - Pt 4.
} // end of while loop
?>
</TABLE>
</CENTER></DIV>
<?php
} // end of if
} // end of for loopHebbs