Jump to content

Recommended Posts

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.
[url=http://www.black-winged.net/truth/]http://www.black-winged.net/truth/[/url]
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
Link to comment
https://forums.phpfreaks.com/topic/17561-pagination-while-randomizing/
Share on other sites

[code]
<?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();
?>
[/code]

See, the problem is that I don't know how to fit that into there.
try[code]
<?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();

?>
[/code]
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.