I currently have a block of code that talks to a certain table in the MySQL database and displays according to both the area and serv columns. I was reading of a method to use ORDER BY RAND() in my MySQL query (which works for me) but I heard that slows down the server and I should randomize my results with PHP instead with shuffle(). How would I modify my code to randomize them properly?
$profiles = "SELECT * FROM profile WHERE area='".$areaid."' AND serv='".$servid."' AND active='1'"; $numresults=mysql_query($profiles); $numrows=mysql_num_rows($numresults);
// rows to return
$limit=10;
if ($numrows == 0)
{
echo "<p></p>";
}
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$profiles .= " limit $s,$limit";
$result = mysql_query($profiles) or die("Couldn't execute query");
echo "";
$count = 1 + $s ;
// now you can display the results returned
while ($row = mysql_fetch_array($result)) {
$instname = $row["inst_name"];
$profileid = $row["profile"];
$logo1 = $row["logo1"];
$city = $row["city"];
$state_abbr = $row["state_abbr"];
$zip = $row["zip"];
$bio = $row["bio"];
$price = $row["rel_fee"];
$years = $row["years"];
$level = $row["level"];
$honors = $row["honors"];
$tagline = $row["tagline"];
echo "<div class=\\"miniprofile\\">
<div class=\\"miniprofile_logo\\">Profile<br><a href=\\"/profile/$profileid\\"><img src=\\"$domain/images/profiles/$logo1\\" alt=\\"\\"></a>
</div>
<div class=\\"miniprofile_head\\"><a href=\\"/profile/$profileid\\" style=\\"font-size:18px;\\">$instname</a>
<br>$city, $state_abbr $zip
<br><br><strong>Service:</strong> $servname
<br><strong>Experience:</strong> $years yrs <strong>Price:</strong> $price
<br><strong>Honors:</strong> $honors
</div>
</div><br><br>" ;
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br>";