NYCPHP Meetup

NYPHP.org

[nycphp-talk] Sssllloooowww Query

Flavio daCosta nyphp at n0p.net
Tue Jul 12 11:21:52 EDT 2005


On 07/12/2005 10:44 AM, harvey wrote:
> I've got some code that works, but it's pretty slllooooww...
> --snip-- 

Unless I am missing something here, cant you just simplify it with a
LEFT JOIN and use only 1 result set?

-- untested --

SELECT ms.subcat_id, ms.subcat_name, msab.show_fid
FROM music_subcats AS ms
LEFT JOIN music_showsandbands as msab
  ON (ms.subcat_id = msab.band_fid AND msab.show_fid = $id)
ORDER BY ms.subcat_name ASC

Then something like:
while ($row = mysql_fetch_assoc($allbands))
{
  $format = '<option value="%s"%s>%s</option>';
  $selected = $row['show_fid'] > 0 ? ' selected' : '';
  printf($format, $row['subcat_id'], $selected, $row['subcat_name'] );
}

-- untested --

Forgive me if I totally missed the boat on this one ;)

Flavio



More information about the talk mailing list