Buddyb3ar Posted August 14, 2006 Share Posted August 14, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/17561-pagination-while-randomizing/ Share on other sites More sharing options...
sasa Posted August 14, 2006 Share Posted August 14, 2006 try[code]<?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}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17561-pagination-while-randomizing/#findComment-74805 Share on other sites More sharing options...
Buddyb3ar Posted August 17, 2006 Author Share Posted August 17, 2006 [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) . "'> </td>\n"; } index_footer($result_final); page_footer();?>[/code] See, the problem is that I don't know how to fit that into there. Quote Link to comment https://forums.phpfreaks.com/topic/17561-pagination-while-randomizing/#findComment-75984 Share on other sites More sharing options...
sasa Posted August 17, 2006 Share Posted August 17, 2006 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) . "'> </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] Quote Link to comment https://forums.phpfreaks.com/topic/17561-pagination-while-randomizing/#findComment-76132 Share on other sites More sharing options...
Buddyb3ar Posted August 18, 2006 Author Share Posted August 18, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17561-pagination-while-randomizing/#findComment-76538 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.