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.
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.
1) Collect ip address and generate random number. 2) Check database "markers" and select all records with that users ip address from the past hour. 3) Check that array to see if random number is already there. 4)
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$r = (rand(1,12))
//$ip = $_SERVER['REMOTE_ADDR'];
require_once('../includes/ran.php');
$result = $conn->prepare("SELECT ip, entrytime, random FROM markers WHERE entrytime>= NOW()- INTERVAL 1 HOUR AND ip LIKE '".$ip."%'");
$result->execute();
//for($i=0; $row = $result->fetch(); $i++){
=====what goes here =======
}
Aucun commentaire:
Enregistrer un commentaire