Best way to perform this type of query

Discussion in 'PHP' started by lazywebprofits, May 16, 2009.

  1. #1
    Hi,

    What is the best way to perform a left outter join query like this as something is causing my server to overload with high mysql cpu usage.

    $cclinks = SELECT linktitle,icon,stime,linkid,mainurl,spot,bold1,bold2 FROM links l LEFT OUTER JOIN clicks c ON (c.linkid2 = l.linkid AND c.userid2='$_SESSION[userid]') LEFT OUTER JOIN votes v ON (v.linkid3 = l.linkid AND v.userid3='$_SESSION[userid]') WHERE l.stats='live' ORDER BY l.spot DESC LIMIT $p2 , 25

    PHP CODE
    
    while($row555 = mysql_fetch_array($cclinks))
      {
      echo "<table border='0' width='80%'>
        <tr>
            <td><img src='images/" . $row555['icon'] . "'><a
            href='viewlink.php?linkid=" . $row555['linkid'] . "' target=''><font size='3'
            face='Verdana' color='" . $row555['color2'] . "'>" . $row555['bold1'] . "" . $row555['linktitle'] . "" . $row555['bold2'] . "</font></a><img
            src='images/" . $row555['icon'] . "'> <font face='tahoma' color='#AD0000' size='2'><strong>  " . $row555['pic1'] . "</strong></font></td>
        </tr>
        <tr>
            <td><a href='votelink.php?id=" . $row555['linkid'] . "&type=up&pp=2&p=$p'><img
            src='images/voteup.gif' border='0'></a><a
            href='votelink.php?id=" . $row555['linkid'] . "&type=down&pp=2&p=$p'><img
            src='images/votedown.gif' border='0'></a> <font
            color='#838383' size='1' face='Verdana'>submitted on " . $row555['stime'] . " > " . $row555['mainurl'] . "<br><br></font></td>
        </tr>
    </table>";
    Code (markup):
     
    lazywebprofits, May 16, 2009 IP