Hi,
I am using Order by Rand() on one of my listing sites to randomise the way the listings are appearing. The trouble is with Rand() is that if you click to view the next 10 listings it totally randomises them again.
Is there a simple way to limit the number of times a record will display.
Thanks
Simon


Hi Simon, You need to pass a
Hi Simon,
You need to pass a seed value to the RAND() function (i.e. use RAND(seed)) and persist the same value throughout your navigation, which you can propagate using a GET variable in the URL, for example "seed".
In other words, on the first view of page 1, choose a random integer using PHP's rand() function (totally unrelated to MySQL's rand() function) and use it as the seed value for RAND(seed) when you construct your SQL, otherwise use the propagated value in $_GET["seed"]:
if (!$_GET["seed"]){
$seed = rand();
}
else
{
$seed = intval($_GET["seed"]);
}
$sql = "SELECT * FROM table ORDER BY RAND(".$seed.")";
...and then make sure that your navigation is passing $seed through to subsequent pages...
Hope this helps!
Cheers,
David.
Thanks David, I will give
Thanks David,
I will give that a go.
Simon
If my navigation link
If my navigation link (created in dreamweaver) looks like this:
<a href="<?php printf("%s?pageNum_tgbc=%d%s", $currentPage, min($totalPages_tgbc, $pageNum_tgbc + 1), $queryString_tgbc); ?>">Next</a>How do I get the .seed variable to be passed through.
Many thanks
Simon
Hi Simon, Try it like this:
Hi Simon,
Try it like this:
<a href="<?php printf("%s?pageNum_tgbc=%d%s&seed=%d", $currentPage, min($totalPages_tgbc, $pageNum_tgbc + 1), $queryString_tgbc,$seed); ?>">Next</a>Cheers,
David.
Yes that seems to work,
Yes that seems to work, many thanks. The only thing is that it seems to add and extra &seed= each page of listings. Not a problem as it doesnt impact the page at all
Thanks for all your help
Simon