Hello,
I have viewed some of the other posts relating to combining queries, and I still don't quite get it. What I would like to do is to perform two queries on a mySQL database, combine the results from those queries, and then display the results individually as line items in a table.
The code that I am using right now is as follows, and any help with this would be appreciated.
revez2002
//////////////////////////////////////////////////////////////////////////
<?php
$query_01 = mysql_query("SELECT
COMPANY.company_name,
PERSONNEL_SCHEDULE.proj_ref_ID,
PERSONNEL_SCHEDULE.personnel_name,
PERSONNEL_SCHEDULE.activity_type,
PERSONNEL_SCHEDULE.activity_start_year,
PERSONNEL_SCHEDULE.activity_start_month,
PERSONNEL_SCHEDULE.activity_start_day,
PERSONNEL_SCHEDULE.activity_finish_year,
PERSONNEL_SCHEDULE.activity_finish_month,
PERSONNEL_SCHEDULE.activity_finish_day
FROM COMPANY, NRT_PERSONNEL_SCHEDULE
WHERE PERSONNEL_SCHEDULE.company_ID=COMPANY.company_id
AND activity_start_year='$schedule_year'
AND activity_start_month='$schedule_month'
ORDER BY COMPANY.company_name");
$personnel_schedule_results = mysql_num_rows($query_01);
$query_02 = mysql_query("SELECT
COMPANY.company_name,
PERSONNEL_SCHEDULE.proj_ref_ID,
PERSONNEL_SCHEDULE.personnel_name,
PERSONNEL_SCHEDULE.activity_type,
PERSONNEL_SCHEDULE.activity_start_year,
PERSONNEL_SCHEDULE.activity_start_month,
PERSONNEL_SCHEDULE.activity_start_day,
PERSONNEL_SCHEDULE.activity_finish_year,
PERSONNEL_SCHEDULE.activity_finish_month,
PERSONNEL_SCHEDULE.activity_finish_day
FROM COMPANY, PERSONNEL_SCHEDULE
WHERE PERSONNEL_SCHEDULE.company_ID=COMPANY.company_id
AND activity_start_year='$schedule_year'
AND activity_start_month='$schedule_month_minus_01'
AND activity_finish_month='$schedule_month'
ORDER BY COMPANY.company_name");
$personnel_schedule_results_02 = mysql_num_rows($query_02);
$the_combined_results = ($personnel_schedule_results + $personnel_schedule_results_02);
for ($i=0; $i < $personnel_schedule_results; $i++) {
$row_01 = mysql_fetch_array($query_01);
}
for ($i=0; $i < $personnel_schedule_results_02; $i++) {
$row_02 = mysql_fetch_array($query_02);
}
$the_combined_query = array_merge($row_01, $row_02);
for ($i=0; $i < $the_combined_results; $i++) {
$row_03 = mysql_fetch_array($the_combined_query);
$proj_ref_ID = stripslashes($row_03["proj_ref_ID"]);
$company_name = stripslashes($row_03["company_name"]);
$activity_type = stripslashes($row_03["activity_type"]);
$personnel_name = stripslashes($row_03["personnel_name"]);
$activity_start_year = stripslashes($row_03["activity_start_year"]);
$activity_start_month = stripslashes($row_03["activity_start_month"]);
$activity_start_day = stripslashes($row_03["activity_start_day"]);
$activity_finish_year = stripslashes($row_03["activity_finish_year"]);
$activity_finish_month = stripslashes($row_03["activity_finish_month"]);
$activity_finish_day = stripslashes($row_03["activity_finish_day"]);
?>
<table border="0" cellpadding="0" cellspacing="0" width="780">
<tr>
<td width="5" bgcolor="#FFFFFF"></td>
<td class="general_content_03" width="<?php echo $company_width; ?>" bgcolor="#FFFFFF"><a class="message_center" href="<?php echo "rms.php?directory=projects&page_name=pro_003&proj_ref_ID=$proj_ref_ID"; ?>"><?php echo "$company_name"; ?></a></td>
<td width="1" bgcolor="#ebebeb"></td>
<?php
$k = "1";
while ($k <= $days_in_month){
echo "<td class='general_content_02_white' height=\"20\" align='center' valign='middle' width='20' ";
if(($activity_start_day <= $k) && ($activity_finish_day >= $k) && ($activity_start_month == $activity_finish_month)) {
echo "background=\"content/schedules/images/$resource_color.jpg\">";
} elseif(($activity_start_day <= $k) && ($activity_start_month <> $activity_finish_month)) {
echo "background=\"content/schedules/images/$resource_color.jpg\">";
} elseif(($k==$first_sunday) || ($k==$second_sunday) || ($k==$third_sunday) || ($k==$fourth_sunday) || ($k==$fifth_sunday)) {
echo "bgcolor=\"#EBEBEB\">";
} elseif(($k==$first_saturday) || ($k==$second_saturday) || ($k==$third_saturday) || ($k==$fourth_saturday) || ($k==$fifth_saturday)) {
echo "bgcolor=\"#EBEBEB\">";
} else {
echo "bgcolor=\"#FFFFFF\">";
}
echo $k;
echo "</td>";
}
?>