title: Check if Random number has been allocated to user in time frame
body: <p>I've got a group of web pages with one image on each. Clicking on the homepage image goes to the next page via an HTML link, which also logs their IP address and the time (using timestamp) they clicked, into an SQL database. Each image is labelled 1.jpg, 2.jpg, etc.</p>
  
  <p>I'm trying to make it more random - so instead of 2.jpg being second, it's rand().jpg - given the latter images are rarely viewed. However, being random, it also causes it to repeat; they end up showing certain pages multiple times and others not at all. 
  I've tried comparing the random number with other random numbers in the database (as per other Stackoverflow questions), to make sure it's unique, but that means one user views more than other.
  It also means that once the users have seen every picture I need to truncate the table or else it won't give any more numbers out.</p>
  
  <p>1) Collect ip address and generate random number.</p>
  
  <p>2) Check database "markers" and select all records with that users ip address from the past hour.</p>
  
  <p>3) Check that array to see if random number is already there.</p>
  
  <p>4) </p>
  
  <pre><code>&lt;?php
  $ip = $_SERVER['REMOTE_ADDR'];
  $r = (rand(1,12))
  
  // $ip = $_SERVER['REMOTE_ADDR'];
  require_once('../includes/ran.php');
  $result = $conn-&gt;prepare("SELECT ip, entrytime, random FROM markers WHERE entrytime&gt;= NOW()- INTERVAL 1 HOUR AND ip LIKE '".$ip."%'");
  $result-&gt;execute();
  // for($i=0; $row = $result-&gt;fetch(); $i++){
  
  =====what goes here =======
  }
  </code></pre>