Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't get the same <code>order by rand()</code> in two subsequent pages - that's the whole point of ordering by rand in the first place.</p> <p>If you want to remember the data on the next page, why not stick the output into a <code>$_SESSION</code> and simply refer to it there?</p> <p>Having said that, you <em>can</em> seed the <code>rand()</code> function with a value along the lines of <code>order by rand(3)</code> which will give you the same results - but that opens up the can of worms where you will need to start passing the same seed to the other pages - which you will probably have to store in a <code>$_SESSION</code> so you end up at square one.</p> <p>Edit: If you want to add 2 new items, use your query as it is, and keep inserting the data into the <code>$_SESSION</code> variable. You can store arrays in there, so it should work a charm. Pull the data back, add it into the session, display all the results from the session. Next page, get two new results, add to session, display all the results from the session.</p> <p>Edit 2:</p> <p>Firstly, make sure you start the session off on each page:</p> <pre><code>session_start(); </code></pre> <p>You want to treat the <code>$_SESSION</code> array just like any other array:</p> <pre><code>$query = "SELECT * FROM foo ORDER BY RAND() LIMIT 2"; $result = mysql_query($query); </code></pre> <p>Not sure how you iterate through your results before you output, so apply as you see fit:</p> <pre><code>howeverYouLoopYouQueryResults { $_SESSION['lastitems'][]=$rowFromYourResult; // This appends the row to the end of the array } </code></pre> <p>Now, when you get to displaying the data you can do something along the lines of:</p> <pre><code>foreach($_SESSION['lastitems'] as $key=&gt;$value) { echo $value . ' &lt;br /&gt;'; // Keep in mind that it will be storing ALL the // items from the row because you used 'select *' // You can see what you selected with: print_r($_SESSION['lastitems']; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload