I'm trying to develop a single table on mysql for my addressbook but when Im trying to display results I feel like I'm doing far too many queries...
Can anyone help me optomise this?
Thanks
Andrew
<?php
$NodeTitles = mysql_query("SELECT * FROM faults, users WHERE faults.openedby = users.userid ".implode(" ", $whereclause)." ORDER by dateopened DESC, timeopened DESC") or die (mysql_error());
while ($row = mysql_fetch_assoc($NodeTitles)) {
$faultid = $row['faultid'];
$clientid = $row['client'];
$referrerid = $row['referredby'];
$fault = $row['fault'];
$openedby = $row['fullname'];
$dateopened = $row['dateopened'];
$timeopened = $row['timeopened'];
//RETRIEVE CLIENT INFO
$client = mysql_query("SELECT * FROM addressbook2 WHERE nameid = '$clientid'") or die (mysql_error());
$row = mysql_fetch_assoc($client);
$clientname = $row['namecompany'];
$clientbranch = $row['namecontactname'];
//RETREIVE REFERRER INFO
$referrer = mysql_query("SELECT * FROM addressbook2 WHERE nameid = '$referrerid'") or die (mysql_error());
$row = mysql_fetch_assoc($referrer);
$refferername = $row['namecompany'];
?>
<tr id="entryRow2358" onMouseOver="this.style.cursor='pointer'" onclick="window.location.href='job.php?faultid=<?php echo $row['faultid'];?>';">
<td class="n" colspan="1"><div title=""><?php echo $faultid;?></div></td>
<td class="" colspan="1"><div title="Company"><?php echo $clientname;?></div></td>
<td class="" colspan="1"><div title="Branch"><?php echo $clientbranch;?></div></td>
<td class="" colspan="1"><div title="Referrer"><?php echo $refferername;?></div></td>
<td class="" colspan="1"><div title="Fault"><?php echo $fault;?></div></td>
<td class="" colspan="1"><div title="Opened By"><?php echo $openedby;?></div></td>
<td class="" colspan="1"><div title="Date Created"><b><?php $date = date_create($dateopened); echo date_format($date, 'j F Y');?></b> <span><?php echo $timeopened;?></span></div></td>
</tr>
<?php
}
?>