Jump to content


Photo

Pagination while randomizing.


  • Please log in to reply
4 replies to this topic

#1 Buddyb3ar

Buddyb3ar
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 August 2006 - 10:02 PM

Well, I'll start out by saying I'm working on a project codenamed "rewrite" for the moment. If you want to see the idea, you can look it up yourself, since that's not the point of this topic.
http://www.black-winged.net/truth/
If you look, you may notice the growing amount of secrets that is becoming a big problem, especially for dial-up users. Also, you may notice that the secrets randomized everytime you refresh.

Since I know it is impossible to keep the secrets randomized while also broken into pages, would it be possible to sort the secrets by IDs and then randomize the the secrets on that page?
If that's possible, how would I do that while keeping them in columns of three?

If you need to see some of the code that I used now, just ask. :/
Thanks,
Dan

#2 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 14 August 2006 - 11:04 PM

try
<?php
$result=mysql_query($sql);
while ($a=mysql_fetch_array($result)) $rows[]=$a;
$keys= array_rand($rows,count($rows));
foreach ($keys as  $key){
	$row=$rows[$key];
	// you code
}
?>


#3 Buddyb3ar

Buddyb3ar
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 17 August 2006 - 12:54 AM

<?php 
 $result = mysql_query("
   SELECT
    *
   FROM
     notes
	ORDER BY RAND()
 ");
 $total = mysql_num_rows($result);
			page_header($css, "");
				index_header($total);
				$number_of_categories_in_row = 3;

 while ($row = mysql_fetch_array($result)) {
 		$text = markerconvert($row[content]);
   $result_array[] = "<div id=\"".$row[ID]."\" class=\"notecontent\" style=\"border: 1px ".$row[bclr]." solid; background-color:".$row[bgclr]."; font-size:10; width:160px; height:100px;\">".$text."</div>";
 }
 mysql_free_result($result);

 foreach ($result_array as $category_link) {
   if ($counter == $number_of_categories_in_row) {
     $counter = 1;
     $result_final .= "\n</tr>\n<tr>\n";
   } else $counter++;
   $result_final .= "\t<td>" . $category_link . "</td>\n";
 }

 if ($counter) {
   if ($number_of_categories_in_row - $counter)
     $result_final .= "\t<td colspan='" .
       ($number_of_categories_in_row - $counter) . "'>&nbsp;</td>\n";


 }
				index_footer($result_final);
			page_footer();
?>


See, the problem is that I don't know how to fit that into there.

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 17 August 2006 - 12:13 PM

try
<?php 
mysql_connect("", "", "");
mysql_select_db("");

$seed = (isset($_GET['seed']) and $_GET['seed'] >= 1) ? intval($_GET['seed']) : rand(1,10000);
$page = (isset($_GET['page']) and $_GET['page'] >= 1) ? intval($_GET['page']) : 1;
$per_page = 3;
$total = mysql_result(mysql_query('select count(*) from notes'),0,0);

$t_pages = ceil($total/$per_page);
$page = $page > $t_pages ? $t_pages : $page;
$start = ($page - 1) * $per_page;
$result = mysql_query("
   SELECT
    *
   FROM
     notes
	ORDER BY RAND($seed)
	LIMIT $start, $per_page
 ") or die(mysql_error());

 while ($row = mysql_fetch_array($result)) { 
 		$text = markerconvert($row[content]);
   $result_array[] = "<div id=\"".$row[ID]."\" class=\"notecontent\" style=\"border: 1px ".$row[bclr]." solid; background-color:".$row[bgclr]."; font-size:10; width:160px; height:100px;\">".$text."</div>";
 
 }
 mysql_free_result($result);

 foreach ($result_array as $category_link) {
   if ($counter == $number_of_categories_in_row) {
     $counter = 1;
     $result_final .= "\n</tr>\n<tr>\n";
   } else $counter++;
   $result_final .= "\t<td>" . $category_link . "</td>\n";
 }

 if ($counter) {
   if ($number_of_categories_in_row - $counter)
     $result_final .= "\t<td colspan='" .
       ($number_of_categories_in_row - $counter) . "'>&nbsp;</td>\n";


 }
 
index_footer($result_final);

if ($page > 1) echo '<a href="?page='.($page-1).'&seed='.$seed.'">PREV </a>'; else echo 'PREV ';
for ($i = 1; $i<=$t_pages;$i++) if ($i != $page) echo '<a href="?page='.$i.'&seed='.$seed.'">| '.$i.' </a>';
else echo "| $i ";
if ($page < $t_pages) echo '<a href="?page='.($page+1).'&seed='.$seed.'">| NEXT</a>';else echo '| NEXT';


page_footer();

?>


#5 Buddyb3ar

Buddyb3ar
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 18 August 2006 - 01:19 AM

OH WOW!
Thank you so much!

It just took a little tweaking of the code here and there, and I got it to work perfectly.
Thank you very very much!
I can now work with the code to change it how I need too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users