Order by Random with Pagination

[php]

<?php $per_page_b = 24; $sql_b = "select * from profile "; $rsd_b = mysql_query($sql_b); $count_b = mysql_num_rows($rsd_b); $pages_b = ceil($count_b/$per_page_b) ?>
	<div id="orta"></div>
</div>
<div id="paging_button">
	<ul>
	<?php
	//Show page links
	for($i_b=1; $i_b<=$pages_b; $i_b++)
	{
		echo '<li id="'.$i_b.'">'.$i_b.'</li>';
	}?>
	</ul>
</div>

[/php]

[php]

<?php $per_page_bs = 4; $sqlc_bs = "show columns from profile "; $rsdc_bs = mysql_query($sqlc_bs); $cols_bs = mysql_num_rows($rsdc_bs); $page_bs = $_REQUEST['page']; $start_bs = ($page_bs-1)*4; $sql_bs = "select id,resim0,adi,fiyat,big,adres from profile where big=1 order by rand() limit $start_bs,4"; $rsd_bs = mysql_query($sql_bs); ?> <?php while ($rows_bs = mysql_fetch_assoc($rsd_bs)) { echo'
  • '; echo''; echo'
    '; echo'
    '; echo'

    '.$rows_bs['adi'].'

    '; echo'

    Fiyat:
    '; echo'' .$rows_bs['fiyat']. ' TL

    '; echo''; echo'
    '; echo''; }?>[/php]

    This is my pagination script.

    I am trying to ramdomize the results so that everyone has a chance of being on the first page, but I don’t know how to hold it after the first page, when I click on page 2, it randomizes the results again, and puts some of the ones on the first page on the second.

    What can i do?

  • I don’t suggest this before because i don’t like this suggestion.

    But …

    You can save in a array the page that show every row.

    $_SESSION[‘pages’] = Array(“1”=>Array(‘X’,‘Y’,‘Z’,…),
    “2”=>Array(‘P’,‘A’,…));

    and do

    if(isset($_SESSION[‘pages’][$pageShow])){
    $sel = “select id,resim0,adi,fiyat,big,adres from profile where id IN (”.join(",",$_SESSION[‘pages’][$pageShow]).")";
    }else{
    // Show randoms that not included
    $temp =array();
    foreach ($_SESSION[‘pages’] as $cla=>$val){
    $temp =array_merge($temp,$val);
    }
    $sel = “select id,resim0,adi,fiyat,big,adres from profile where id NOT IN (”.join(",",$temp).") order by rand";
    }

    Sponsor our Newsletter | Privacy Policy | Terms of Service