ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Random entries not so random - old mysql to blame?

October 23, 2007 3:05pm

Subscribe [3]
  • #1 / Oct 23, 2007 3:05pm

    Simon Clayson

    38 posts

    I’ve just revisited an old installation of mine to resurrect a random entry feature. The parameter is set to limit=“1”, and I know the entries are fine when I change it to limit=“4”.

    I can only ever get to see two of these entries - the newest ones by ID. I’m sure this was to do with a troublesome version of mysql - 3.23.52 - I lost the link that pointed to this as the issue.

    Can anyone confirm this?

    I’m also on Build 20070627 - php version is at 4.22

    I know, move hosts…

  • #2 / Oct 23, 2007 8:00pm

    Sue Crocker

    26054 posts

    Hi, Simon. You’re a few builds behind. Any chance you can upgrade to the newest build which will put us on the same footing?

  • #3 / Oct 24, 2007 2:51am

    Simon Clayson

    38 posts

    On the same build now, issue persists.

  • #4 / Oct 24, 2007 11:20am

    Robin Sowell

    13255 posts

    Hm- searched around and haven’t spotted it as a mysql version related issue.  Which doesn’t mean it’s not.  But- could be cache related as well.  Try this and see if it works:

    {exp:query sql="SELECT title FROM exp_weblog_titles WHERE entry_id != '{current_time}' ORDER BY RAND() LIMIT 1"}
    {title}
    {/exp:query}

    Should eliminate any cache issues and it’s as simple as I can get it for testing whether it’s the query itself.

    Also- I’m going to shift this over to ‘Tech Support’.

  • #5 / Oct 24, 2007 11:35am

    Simon Clayson

    38 posts

    Not quite sure what to change, I need to specify the category, tried that and got lost! - I’m not sure about the (current_time) part… Here’s my tag:

    {exp:weblog:entries weblog="{my_weblog}" orderby="random" dynamic="off" disable="pagination|member_data|trackbacks" rdf="off" category="1" limit="1"}
        <div id="main_area" class="{my_template_group}_area">
            <a href="http://{path=xxx}">{main_image}</a>
        </div>
    {/exp:weblog:entries}

    Thanks

  • #6 / Oct 24, 2007 11:42am

    Robin Sowell

    13255 posts

    No- just stick the exact code I pasted in some template.  It’s just a test to see if rand() is working.  If the query works- we’ll go from there.  Make sense?  It’s not a fix- just a test.

  • #7 / Nov 23, 2007 3:18pm

    Oldtimer

    10 posts

    Hm- searched around and haven’t spotted it as a mysql version related issue.  Which doesn’t mean it’s not.  But- could be cache related as well.  Try this and see if it works:

    {exp:query sql="SELECT title FROM exp_weblog_titles WHERE entry_id != '{current_time}' ORDER BY RAND() LIMIT 1"}
    {title}
    {/exp:query}

    Should eliminate any cache issues and it’s as simple as I can get it for testing whether it’s the query itself.

    Also- I’m going to shift this over to ‘Tech Support’.

    We were suspecting that there might be some random problems as well. I used the code above and I do see a different title each time. Does that mean it’s working?

  • #8 / Nov 25, 2007 12:09pm

    Robin Sowell

    13255 posts

    Yep- it’s working as far as I can see.  Basically- I suspect you’ve got query caching/dynamic caching on.  And since the rand() query is the same actual query each time- it just serves up the cached results rather than doing a new query.  Putting he current_time bit in is a cheat- it makes for a new query every page load- thus the cached query isn’t used and you get a new query each time- generally with a new result.

    I use the trick if using any kind of caching that would likely result in dupes with rand.  Think it will do the trick- or do we need to dig into your cache options?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases