NYCPHP Meetup

NYPHP.org

[nycphp-talk] Sssllloooowww Query

harvey list at harveyk.com
Tue Jul 12 10:44:31 EDT 2005


Hi NYPHP,

I've got some code that works, but it's pretty slllooooww...

There are about 4,000 bands in the overall list, and we're displaying them 
all, so I'm sure that's part of it.

But I have a feeling the major slowdown is the loop in the middle that 
checks to see if the band is performing in the selected concert.

Are there any obvious modifications to the code that would speed it up a bit?

I tried a foreach loop on $row_showbands instead of the do-while on 
$showbands, but couldn't quite get it to work properly. I think the reset 
was not working?

Thanks in advance...

Harvey


This query gets the full list of band names to display alphabetically.

<?php mysql_select_db($database_cititour, $cititour);
$query_allbands = "SELECT subcat_id, subcat_name FROM music_subcats ORDER 
BY subcat_name ASC";
$allbands = mysql_query($query_allbands, $cititour) or die(mysql_error());
$row_allbands = mysql_fetch_assoc($allbands);
$totalRows_allbands = mysql_num_rows($allbands); ?>

This query gets the id's of the particular bands in the selected concert.

<?php mysql_select_db($database_cititour, $cititour);
$query_showbands = "SELECT band_fid FROM music_showsandbands WHERE show_fid 
= $id";
$showbands = mysql_query($query_showbands, $cititour) or die(mysql_error());
$row_showbands = mysql_fetch_assoc($showbands);
$totalRows_showbands = mysql_num_rows($showbands); ?>

This query shows the full list of bands in a list box, with the specific 
concert bands highlighted.

<select name="band_fid[]" size="20" multiple id="band_fid[]">
	<option value="0">------</option>
	<?php do { ?>
		<option value="<?php echo $row_allbands['subcat_id']?>"
		<?php do {
			if ($row_allbands['subcat_id'] == $row_showbands['band_fid']) { echo " 
selected"; }
		 } while ($row_showbands = mysql_fetch_assoc($showbands)); ?>>
		<?php mysql_data_seek($showbands, 0) ?>
		<?php echo $row_allbands['subcat_name']; ?>
		</option>
	<?php } while ($row_allbands = mysql_fetch_assoc($allbands)); ?>
</select>




More information about the talk mailing list