Output table formatting

Hi guys,

Im trying to figure out how i can display a query result without displaying the same info twice.

Lets say i have a DB with 2 tables. Table1 & Table2.
TABLE 1
customer_id l company_name l address l

TABLE 2
id l equip_id l hardware l expiry l

The ‘customer’ and ‘id’ field are the primary keys. ‘equip_id’ and ‘customer_id’ are the same. So a customer is listed in table 1 but all their hardware is listd in table 2 and item per row, so there will be multiple equip_id’s of the same value for each customer.

I’ve got my query working great thanks to help from this forum but i can seem to format the output how i want.

im after:
company_name
_____________hardware l expiry
_____________hardware l expiry
company_name
_____________hardware l expiry
_____________hardware l expiry

and so on…
this is what i have now but it lists the company name for every hardware item.


<?php   QUERY HERE    ?>
	<table id="cust_table">
	<th>Company</th>
	<th>Manufacturer</th>
	<th>Description</th>
	<th>Expiry Date</th>
	<?php
		if ($num_rows < 1) {
				echo "No match found! Please go back and try again.";
			} else {
		while ($row = mysql_fetch_assoc($result)) {
	?>
	<tr>
		<td><?php echo $row['company_name']; ?></td>
		<td><?php echo $row['manufacturer']; ?></td>
		<td><?php echo $row['description']; ?></td>
		<td><?php echo $row['end_date']; ?></td>
	</tr>
	<?php
	}
	}
	?>
	</table>

Use a variable to store the current company name (starting with ‘’). Inside the loop, check if the company name has changed. If so, display it and store it in the variable.

Sort of makes sense but a little over my head…

Any examples?

Appreciate the response.

Thanks.
Mark


    // initialize the 'company name storage' variable
    $companyname = '';
    while ($row = mysql_fetch_assoc($result)) {
?>
     <tr>
         <td>
<?php 
            // check if the company name has to be displayed
            if ($row['company_name'] != $companyname) {
               echo $row['company_name']; 
               $companyname = $row['company_name']; 
            }
?>
         </td>
         <td><?php echo $row['manufacturer']; ?></td>
         <td><?php echo $row['description']; ?></td>
         <td><?php echo $row['end_date']; ?></td>
     </tr>
<?php
     } 

appreciate it, works a treat.

Many thanks.

More accurate formatting:


<?php
// initialize the 'company name storage' variable
$companyname = '';
while ($row = mysql_fetch_assoc($result)) {
    ?>
     <tr>
    <?php 
        // check if the company name has to be displayed
        if ($row['company_name'] != $companyname) {?>
           <td colspan="3"><?php echo $row['company_name']; ?></td>
        </tr>
        <tr>
           <?php $companyname = $row['company_name']; 
        }
    ?>
     <td><?php echo $row['manufacturer']; ?></td>
     <td><?php echo $row['description']; ?></td>
     <td><?php echo $row['end_date']; ?></td>
    </tr>
    <?php
     }
?>