I currently am using mysql and php to display 9 random results from my table of about 1100 records.
Would it be possible to have a next and previous button even though it’s random? I looked at a couple of the examples already posted here but they seem to be application/project specific. Here is what my code looks like..
function executeQuery($searchKey)
{
if ($searchKey == null)
{
$query = "SELECT DISTINCT flightNumber, flightCity FROM allFlights LIMIT 0,9";
//DEBUG -echo "<p>$searchKey</p>";echo "<p>$query</p>";
}
else
{
//DEBUG -echo "<p>$searchKey</p>";echo "<p>var not null</p>";
$query = "Select distinct * from allFlights where flightCity LIKE '%$searchKey%' LIMIT 0,9";
//DEBUG -echo "<p>$searchKey</p>";echo "<p>$query</p>";
}
$result=mysql_query($query);
$numrow=mysql_numrows($result);
if ($numrow === 0)
{
$query = "Select distinct * from allFlights where flightNumber LIKE '%$searchKey%' LIMIT 0,9";
$result=mysql_query($query);
$numrow=mysql_numrows($result);
}
return $result;
}
function populate ()
{
$searchKey = mysql_real_escape_string($_POST["search"]); //assigns user input to searchKey variable
//DEBUG -echo "<p>$searchKey</p>";
$result=executeQuery($searchKey);
$numrow=mysql_numrows($result);
if ($numrow == 0)
{
echo "<center><p><b> No results found, please try another keyword.</p></center></b>";
}
else
{ display results. -- this part i have working.
}
I prefer upon loading the page this happens:
-The current position with respect to the # of flights available are listed. (Now showing 9 of 1100 flights)
-9 random flights are displayed.
-Next button that will show the next 9 flights (random would be nice.)
-Previous button that will show the previous(original) 9 flights (random would be nice.)
When all is said and done I would like to be able to load the page identify the 9 random flights, press next identify the new 9 random flights, then previous and identify the original 9 random flights.
Any help is much appreciated.
You can use ORDER BY RAND(seed) to give a pseudorandom order that is repeatable:
Adjust the offset to move back and forwards through the results. The seed can be any integer, and you can change it if you want to re-randomize the order, but you must use the same seed when pressing back or forward.