I am trying to improve my switch statement to make it more random. Currently I am trying to randomize profiles. Two profiles are displayed at a single time one above the other. These profiles are on a slideshow and fade in and out every 2.5 seconds. I do not want the same profile to show up at the same time (both on top and bottom) when the webpage is loaded. Thank you in advance for any input you might have. I have created the two switch statements as follows:
<div id="Slider">
<?php
$getSliderInfoQuery = "SELECT f_name, l_name, city, zipcode, pst.name as state_id, book_types, profile_photo, profile_url, prt.rating FROM book_readers ps left join book_states pst on pst.state_id = ps.state_id left join book_reviews prt on prt.user_id = ps.user_id WHERE promoted_reader = 1 ORDER BY ";
$pickRow = mt_rand(1, 6);
$pickRow = mt_rand(1, 6);
switch($pickRow) {
case 1:
$getSliderInfoQuery .= "l_name";
break;
case 2:
$getSliderInfoQuery .= "f_name";
break;
case 3:
$getSliderInfoQuery .= "city";
break;
case 4:
$getSliderInfoQuery .= "profile_photo";
break;
case 5:
$getSliderInfoQuery .= "l_name DESC";
break;
case 6:
$getSliderInfoQuery .= "city DESC";
break;
<div id="Slider2">
<?php
$getSliderInfoQuery = "SELECT f_name, l_name, city, zipcode, pst.name as state_id, book_types, profile_photo, profile_url, prt.rating FROM book_readers ps left join book_states pst on pst.state_id = ps.state_id left join book_reviews prt on prt.user_id = ps.user_id WHERE promoted_reader = 1 ORDER BY ";
$pickRow = mt_rand(1, 6);
switch($pickRow) {
case 1:
$getSliderInfoQuery .= "f_name";
break;
case 2:
$getSliderInfoQuery .= "l_name";
break;
case 3:
$getSliderInfoQuery .= "city";
break;
case 4:
$getSliderInfoQuery .= "profile_photo";
break;
case 5:
$getSliderInfoQuery .= "city DESC";
break;
case 6:
$getSliderInfoQuery .= "l_name DESC";
break;
}
$sliderResult = mysql_query($getSliderInfoQuery);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…