mididelight
05-09-2006, 09:21 PM
Hello,
The following code runs a while loop that queries the database X number of times (no more than 4 times). This will happen for several different pages on my site. I was wondering if running queries like this is too taxing for a database to handle? The queries are fetching normal select data, the where claus is determined by a comma delimited list of ID's of other rows.
Here is the code, what do you think?
<?php if ($current_category["related"] <> NULL){ ?>
<div class="right-module-style">
<h4>Artists Other Users Preferred</h4>
<ul>
<?php
// Get Related Artists
$related = $current_category["related"];
$related = explode(",",$related);
$x = 0;
$size = sizeof($related);
while ( $x < $size ) {
$result = mysql_query("
SELECT id, name
FROM dir_categories
WHERE dir_categories.id = '$related[$x]' ");
$row = mysql_fetch_row($result);
$artist = $row[1];
$artist = strtolower($artist);
$artist = ereg_replace(" |,|/|&|&|'|\.","_",$artist);
echo '<li><a href="/pages/'.$row[0].'/'.$artist.'" title="'.$row[1].'">'.$row[1].'</a></li>'."\n";
$x++;
}
?>
</ul>
</div>
<?php } ?>
The following code runs a while loop that queries the database X number of times (no more than 4 times). This will happen for several different pages on my site. I was wondering if running queries like this is too taxing for a database to handle? The queries are fetching normal select data, the where claus is determined by a comma delimited list of ID's of other rows.
Here is the code, what do you think?
<?php if ($current_category["related"] <> NULL){ ?>
<div class="right-module-style">
<h4>Artists Other Users Preferred</h4>
<ul>
<?php
// Get Related Artists
$related = $current_category["related"];
$related = explode(",",$related);
$x = 0;
$size = sizeof($related);
while ( $x < $size ) {
$result = mysql_query("
SELECT id, name
FROM dir_categories
WHERE dir_categories.id = '$related[$x]' ");
$row = mysql_fetch_row($result);
$artist = $row[1];
$artist = strtolower($artist);
$artist = ereg_replace(" |,|/|&|&|'|\.","_",$artist);
echo '<li><a href="/pages/'.$row[0].'/'.$artist.'" title="'.$row[1].'">'.$row[1].'</a></li>'."\n";
$x++;
}
?>
</ul>
</div>
<?php } ?>