Joining tables
Posted: Sun Oct 01, 2006 11:40 am
I've started working on joining certain data from certain tables but I'm struggling a tiny bit in outputting the data. At the moment 1 table contains a company name with a unique ID that relates to the company. The other table contains a customer name which has an ID that correspondes to the ID from the first table, a first name, a surname and a product. This is the code I have at the moment:
But it outputs every customer entry 5 times in the table, each one with each of the companys names.
http://stesbox.co.uk/php/test/join.php
Can anyone help me out with this?
Ste,
Code: Select all
mysql_connect("x", "x", "x");
mysql_select_db("resellers");
$query = mysql_query("SELECT r.ResellerName, c.fName, c.sName, c.package FROM resellerID r JOIN customers c");
?><table border="1" cellpadding="1" cellspacing="1">
<tr>
<th> Reseller Name </th>
<th> First Name </th>
<th> Last Name </th>
<th> Package </th>
</tr><?php
while ($results = mysql_fetch_array($query)) {
?><tr>
<td> <?php echo $results['ResellerName']; ?> </td>
<td> <?php echo $results['fName']; ?> </td>
<td> <?php echo $results['sName']; ?> </td>
<td> <?php echo $results['package']; ?> </td>
</tr><?php
}
?></table><?phphttp://stesbox.co.uk/php/test/join.php
Can anyone help me out with this?
Ste,