hello..

i am using random query with pagination. but i am getting same results in second page also.

Two things I need to make happen:

1. click on a result, you click the back button, results are in same order.
2. You get a paginated list of results in a random order, but the order stays the same as you traverse the pagination.

how to solve this?

this is my query

if($services!=''){
//echo $_REQUEST['search_text'];exit;
$otherParams="&services=".$services;
//echo $otherParams;exit;
}
<? if($services!='')
{
//echo "abc";exit;
$seltalent=mysql_query("select * from localtalent where services='$services' && status=1 order by RAND()  ");
            $seltalent1=mysql_query("select * from localtalent where services='$services' && status=1 order by RAND()  LIMIT $start , $q_limit");
            $num=mysql_num_rows($seltalent);
}else{
            $seltalent=mysql_query("select * from localtalent where status=1 order by RAND() ");
            $seltalent1=mysql_query("select * from localtalent where status=1 order by RAND() LIMIT $start , $q_limit");
            $num=mysql_num_rows($seltalent);
            }
            if($num>0)
            {
            while($fetchtalent=mysql_fetch_array($seltalent1))
            
            { 
            
            ?>

I achieved this using the serialize() function. You have to store the database results as a serialized array then unserialize it on the next page.

Basic outline would be as follows:

Get result set

If first page then serialize results and save to a session variable.

If page number is greater then one then retrieve results from session and unserialize. USe this as your resultset instead of database.

Note you may run into trouble if result set is too large.

i got it. solution here

<?
              if($services!='')
{
unset($_SESSION['localtalent_id']);
}
              
             if ($_SESSION['localtalent_id']!=''){

$_SESSION['localtalent_id'] = array_unique ($_SESSION['localtalent_id']); 

  $localtalent_id = array_slice($_SESSION['localtalent_id'],$start,5);

  }
if (!count($localtalent_id) || $_SESSION['localtalent_id']=='') {
$_SESSION['localtalent_id'] = array();
//no IDs have been selected
  //randomly select IDs and store them in session
 
  if($services!='')
{

$r1 = mysql_query("select * from localtalent where services='$services' && status=1 order by RAND()");

  $r = mysql_query("select * from localtalent where services='$services' && status=1 order by RAND()");
  
  }else{

  $r1 = mysql_query("select * from localtalent where status=1 order by RAND()");
  $r = mysql_query("select * from localtalent where status=1 order by RAND()");
  }
  $num=mysql_num_rows($r1);

  while ($fetch_talent= mysql_fetch_array($r)){ 

  $_SESSION['localtalent_id'][]=$fetch_talent[auto_id];

  }
  // extract 5 IDs to display per page

  $_SESSION['localtalent_id'] = array_unique ($_SESSION['localtalent_id']);
  //echo count($_SESSION['localtalent_id']);exit;  
 
  $localtalent_id = array_slice($_SESSION['localtalent_id'], $start,5);
}
             ?>
             <? 
             if (count($localtalent_id)!='') {
// we have IDs to select from the database
//print_r($localtalent_id);
foreach($localtalent_id as $local_id){


  $seltalent = mysql_query("SELECT * FROM localtalent WHERE auto_id=$local_id");
  $fetchtalent=mysql_fetch_array($seltalent);
 
            ?>
             <tr>
               <td align="left" valign="top">
               <div class="local_talent">
               <div class="local_talent_top"></div>
               <div class="local_talent_middle">
                   <table width="98%" border="0" cellpadding="0" cellspacing="0">
                   
                       <tr>
                         <td align="left" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                           
                               <tr>
                                 <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                   
                                   
                                   

                                   <tr>
                                     <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="4">
                                         <tr>
                                           <td height="30" colspan="3" align="left" valign="top" class="product_hrd_org"><div align="left" class="product_hrd_org"><? echo ucwords($fetchtalent['services']) ?></div></td>
                                           <td width="100"  height="100" rowspan="7" align="left" valign="top">
                                             <? if($fetchtalent['image']!=''){ ?>
                                             <img src="localtalent/100X100/<?=$fetchtalent['image']?>"/>
                                             <? }?>
                                             
                                                                                 </td>
                                         </tr>
                                         <tr>
                                        
                                         <td align="left" valign="top" class="grey_text">Name:</td>
                                         <td width="2" align="left" valign="top">&nbsp;</td>
                                         <td width="250" align="left" valign="top"><strong><? echo ucfirst($fetchtalent['name']); ?></strong></td>
                                          </tr>
                                       <tr>
                                         <td align="left" valign="top" class="grey_text"><div align="right">Company name:</div></td>
                                         <td align="left" valign="top">&nbsp;</td>
                                         <td width="250" align="left" valign="top"><strong><? echo ucfirst($fetchtalent['company']); ?></strong></td>
                                       </tr>
                                       <tr>
                                         <td align="left" valign="top" class="grey_text">Email Address:</td>
                                         <td align="left" valign="top">&nbsp;</td>
                                         <td width="250" align="left" valign="top"><strong><? echo $fetchtalent['email']; ?></strong></td>
                                       </tr>
                                       <tr>
                                         <td align="left" valign="top" class="grey_text">Phone Number:</td>
                                         <td align="left" valign="top">&nbsp;</td>
                                         <td width="250" align="left" valign="top"><strong><? echo $fetchtalent['phone']; ?></strong></td>
                                       </tr>
                                       <tr>
                                         <td align="left" valign="top" class="grey_text">Website Address:</td>
                                         <td align="left" valign="top">&nbsp;</td>
                                         <td width="250" align="left" valign="top"><a href="<? echo $fetchtalent['website']; ?>" style="text-decoration:none;" target="_blank"><strong><? echo $fetchtalent['website']; ?></strong></a></td>
                                       </tr>
                                     
                                       <tr>
                                         <td align="left" valign="top" class="grey_text_2">Services Offered:</td>
                                         <td align="left" valign="top">&nbsp;</td>
                                         <td width="440"align="left" valign="top" colspan="2" style="padding-right:10px;"<strong><? echo $fetchtalent['servicesoffered']; ?></strong></td>
                                       </tr>
                                       
                                     </table></td>
                                     </tr>
                                 </table></td>
                               </tr>
                               <tr>
                                 <td>&nbsp;</td>
                               </tr>
                             
                         </table></td>
                       </tr>
                   
              </table>
            </div>        <div class="local_talent_bottom"></div></div>              </td>
             </tr>
            <? }?><tr><td  align="right"><span class="pagetext">
            <?php
              if($otherParams!='') {
                paginate4($start,$q_limit,count($_SESSION['localtalent_id']),$filePath,$otherParams);
                }else{
                paginate4($start,$q_limit,count($_SESSION['localtalent_id']),$filePath,"");
                }
                ?>
              </span></td></tr>
            <? }else{
            ?>
             <tr>
               <td align="left" valign="top">
              <? 
              //echo 
              //echo $otherParams;exit;
              if($otherParams!='') {?>
             No One Matched With Search Criteria.try again    <? }?>     </td>
             </tr>
            <? }?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.