vendredi 7 avril 2017

Random PHP/MySQL query updating every few minutes, not on refresh

I have two tables in a MySQL databases, one of images, one of text:

Table 1 (images):

<img src="pngs/000.png">
<img src="pngs/001.png">
<img src="pngs/002.png">
...
<img src="pngs/199.png">

Table 2 (text):

"This is text 0."
"This is text 1."
"This is text 2."
...
"This is text 1999."

I would like the page to display a random image, and ten lines of random text, which update on each access and every refresh.

So far, I have this working perfectly on a local Web Apache server. However, when uploaded online, there are a couple of issues:

  1. The results update to new random results every ~five minutes, rather than on each refresh.
  2. The results are the same across devices, rather than unique for each instance.

I am currently using the following method to select a random row from the MySQL database:

$query  = 'SELECT * FROM pngs ORDER BY RAND() LIMIT 1';

And referring to that script in the HTML with:

<div class='img'><?php include('pngs.php');?></div>

Is the delay in updating the images a problem with this implementation? Or am I misunderstanding the MySQL/PHP infrastructure and should be using Javascript instead?

I would greatly appreciate any advice on how to produce the desired functionality.




Aucun commentaire:

Enregistrer un commentaire