html - Randomised content from PHP script not refreshing on reload -


this question has answer here:

i trying implement site displays random image every time page refreshed.

currently, images in directory "/pngs/", , have mysql database indexed rows:

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

then, in html:

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

referring php script, selects random row database:

<?php   require_once 'login.php';   $conn = new mysqli($hn, $un, $pw, $db);   if ($conn->connect_error) die($conn->connect_error);   $query  = "select * pngs";   $result = $conn->query($query);   if (!$result) die($conn->error);   $rows = $result->num_rows;   $r = rand(1,$rows);   $result->data_seek($r);   $row = $result->fetch_array(mysqli_assoc);   echo $row['png'];   $result->close();   $conn->close(); ?> 

at moment, works cross-browser when run local apache web server. when uploaded , run actual site, images remain fixed on refresh.

clearing cache , refreshing produces desired effect, perhaps issue cache? have tried various cache clearing , no-cache methods, none of have worked.

one thought perhaps php script run once results stored in cache? in case how force php script run each refresh?

another thought perhaps using javascript display random image easier , better solution? willing adapt if so.

would appreciate advice, relative newbie here.

thanks.

edit

thanks replies, image cache workaround solves issue images.

however initial problem more general , occurs text.

for example, if use mysql database indexed rows of text:

"first text displayed." "second text displayed." "third text displayed." "fourth text displayed." 

and if use similar php script shown above, text displayed correctly randomized initially, remains same when page refreshed.

so intended question more general: how ensure php/mysql query executed on every refresh, rather first result cached , repeated?

edit 2

apologies further edit, not sure whether start new question now...

so seems may have misunderstood how php/mysql infrastructure work...

intended functionality: each page view returns different result mysql database, resulting in different images/text each user on every refresh.

current functionality: each page view returns same results mysql database, across various users. results displayed random, , update, every few minutes instead of every refresh. results displayed same across users, implying php script / mysql query happening server-side, rather uniquely each user.

thinking may have decided use wrong infrastructure intended result, considering trying implementation in javascript.

you can mysql query itself, executing order rand()

select *  `pngs` order rand( ); 

this execute query , produce result randomnly row results


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -