Jump to content

random pagination


czukoman20

Recommended Posts

so just

$x=array(1=>3,2=>1,3=>5);

$_SESSION[count] =$_SESSION['count'] +1;
if ($_SESSION['count']  == count($x)){
$_SESSION['count'] = 1;
}
$data = mysql_query("SELECT * FROM users WHERE userid_2 = {$x[$_SESSION['count']]}") or die(mysql_error());
shuffle($data);

 

cause thats what i thought u said... pluse this code isn't showing my page numbers and its still the same

Link to comment
Share on other sites

well it works... but the randomization is still the same.. oy

 

would it have to do with anything in the second SELECT function

$x=array(1=>3,2=>1,3=>5);

$_SESSION[count] =$_SESSION['count'] +1;
if ($_SESSION['count']  == count($x)){
$_SESSION['count'] = 1;
}
$data = mysql_query("SELECT * FROM users WHERE userid_2 = {$x[$_SESSION['count']]}") or die(mysql_error());

$rows = mysql_num_rows($data);

//This is the number of results displayed per page
$page_rows = 4;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("SELECT * FROM users WHERE userid_2 $max") or die(mysql_error());

yehey at last it works..

 

you get the data from your db right?

now to select the banner do something like

 

select * from banner order by id rand()  that should be the value of your $X

you only have to query that once so you have to use session again to determine if you're finish querying

eg...

 

once the page loads set the session

if (!isset($_SESSION['loads']) ){

     $_SESSION['loads'] = true;
     $x ='select * from banner order by id rand()';
     $x2 = mysql_query($x);
     
      while($x3 = mysql_fetch_array($x2)){
      $x[] = $x3 ;
      }
}

note not tested but that should work

Link to comment
Share on other sites

I'm just lost.. just to recap what is going on for people who dont feel like reading the whole topic. i am trying to get my pagination to display randomly. which it does. but it only has 1 random order.. which is pointless. soo here is the code

 

 <?php
// Connects to your Database
@mysql_connect("db1093.perfora.net", "dbo215169417", "TkA.Btc7") or die(mysql_error());
@mysql_select_db("db215169417") or die(mysql_error());

//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

//Here we count the number of results
//Edit $data to be your query
$data = mysql_query("SELECT * FROM users WHERE userid_2 > '0' ORDER BY rand()") or die(mysql_error());
$rows = mysql_num_rows($data);

//This is the number of results displayed per page
$page_rows = 1;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("SELECT * FROM users WHERE userid_2 > 0 $max") or die(mysql_error());

//This is where you display your query results
while($values = mysql_fetch_array( $data_p ))
{
//Print $values'Name'];
echo "<br>";;
   $username = $values['username'];
   echo " <img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.jpg\" width=\"500\" height=\"95\"> <br>";
   echo ".::. Company: " . $values['companyname'] . "<br>  ";
   echo "Short info: " . $values['info'] . "<br> ";
if($session->logged_in){
   echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\">.::. Contact Us </a> <br />";
   }
else{
   echo "<a href=\"http://www.adworld-online.com/submit2.php?user=$username\">.::. Contact Us </a> <br />";
   }
}
echo "<p>";

// This shows the user what page they are on, and the total number of pages
echo " --Page $pagenum of $last-- <p>";

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
}

//just a spacer
echo " ---- ";

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}
?>

 

that was designed initially to pic fromt he database numbers 1 - users=5 and randomize them in an order like so 14523 something like that .. . the problem is i want a new randomization not that same order everytime a user makes a look at the page.. so its fair to all my users and nobody gets the front page everytime

 

OY thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.