I have a page on my site where I would like to list out the separate instances in which a customer ordered a part or brought their bike in for service. The data for each of these is contained in separate tables. Ultimately I'll be sorting these by date and using ORDER BY and COALESCE to make this work, but first I have to pull the data and I can't figure out how to do it.
Since the two tables are unrelated I won't be using a JOIN to combine data and I thought I might use a UNION but then learned that the data and number of columns for unions needs to be similar. I saw someone somewhere just throwing up a comma but I can't get mine to work.
Here's what I've got:
$result = mysql_query("SELECT
p.part_id,
p.part_num,
p.descr,
p.vendor,
p.date_entered,
p.date_ordered,
p.date_rcvd,
s.serv_id,
s.make,
s.model,
s.yr,
s.vin,
s.mileage,
s.in_date,
s.out_date
FROM parts p, services s
WHERE cust_id = '$cust_id'");
if (mysql_num_rows($result) == 0) {
$transactions = array();
} else {
while ($row = mysql_fetch_assoc($result)) {
$transactions[] = $row;
}
}
Later on
<? foreach ($transactions as $transaction): ?>
<? if($transaction['part_id'] && $transaction['part_id'] != "") { ?>
[DISPLAY PART INFO]
<? } elseif($transaction['serv_id'] && $transaction['serv_id'] != "" { ?>
[DISPLAY SERVICE INFO]
<? } ?>
<? endforeach; ?>
Any ideas?