Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2016-10-25 10:10:46
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Order by rand() work on Safari, not on Chrome and Firefox
I want to randomly display 6 images ids from the txp image table.
With Safari it works as expected.
But with Chrome and Firefox, I have every time the same sequence of pictures unless I empty the browser cache.
My code :
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<txp:smd_query query="SELECT id
FROM txp_image
WHERE category='banniere-haut' ORDER BY RAND() LIMIT 6">
{id},
</txp:smd_query>
</body>
</html>
Same problem with smd_random_banner.
How to make it also works well on FFox and Chrome?
Last edited by jpdupont (2016-10-25 12:10:27)
Offline
Re: Order by rand() work on Safari, not on Chrome and Firefox
Hi JD,
It has to do with the way ff is dealing with its cache. If you click shift+refresh, the ids change.
By the way you can do what you are trying to do using native txp tags
<txp:images category="banniere-haut" sort="ran()" limit="6" wraptag="" break=",">
<txp:image_info type="id" />
</txp:images>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Order by rand() work on Safari, not on Chrome and Firefox
Try to append
<txp:php>header('Cache-Control: no-cache, no-store, must-revalidate');</txp:php>
when you need the content to be refreshed.
Offline
#4 2016-10-25 10:42:30
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Re: Order by rand() work on Safari, not on Chrome and Firefox
Thanks colak for the txp:images tip !
@etc : now my code is
<txp:php>header('Cache-Control: no-cache, no-store,
must-revalidate');</txp:php>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<txp:smd_query query="SELECT id
FROM rox_txp_image
WHERE category='banniere-haut' ORDER BY RAND() LIMIT 6">
{id},
</txp:smd_query>
</body>
</html>
without success …
Offline
Re: Order by rand() work on Safari, not on Chrome and Firefox
Weird, you server still sends just no-cache
. Well, try to set Send "Last-Modified" header?
(in Publish
preferences) to No
.
Offline
#6 2016-10-25 10:54:13
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Re: Order by rand() work on Safari, not on Chrome and Firefox
@etc :
It’s the Send "Last-Modified" header to "no"
!!!
I remove your txp:php line and actually, it’s OK ! Thanks ! :-)
Offline
Re: Order by rand() work on Safari, not on Chrome and Firefox
Fine, but I’m curious why header
does not work. Is your Allow PHP in pages?
preference set to Yes
?
Offline
#8 2016-10-25 12:00:33
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Re: Order by rand() work on Safari, not on Chrome and Firefox
The Allow PHP in pages?
preference is set to Yes
.
Offline