Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp/MySQL help - random daily pick?
    text
    copied!<p>I'm trying to get a pick from my DB that would last for a day (daily pick). I use the following code:</p> <pre><code>$query = 'SELECT * FROM table ORDER BY rand() LIMIT 1 </code></pre> <p>But as you can see it only gives me a random pick from the table, and every time I refresh the page it gets me a new random pick. How can I make the pick to last for a whole day?</p> <p>Thanks in advance &lt;3</p> <hr> <p>I'm trying this: </p> <pre><code>$query = "SELECT * FROM table ORDER BY rand(" . date("Ymd") . ") LIMIT 1"; </code></pre> <p>But I get the following error: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource. This is the part that gets broken: </p> <pre><code>$results = mysql_query($query); while($line = mysql_fetch_assoc($results)) </code></pre> <hr> <p>So... it should look like this, right? (I mean, choosing the daily random pick?)</p> <pre><code>$dailyPick = 'SELECT * FROM table ORDER BY rand() LIMIT 1'; $cacheKey = 'dailyPick'. date('dmY'); if($cache-&gt;has($cacheKey)) { $dailyPick = $cache-&gt;get($cacheKey); } else { // hit database $dailyPick = $cache-&gt;save($cacheKey); } </code></pre> <hr> <p>I'm trying this now:</p> <pre><code>$dailyPick = 'SELECT * FROM table ORDER BY rand() LIMIT 1'; $cacheKey = 'dailyPick'. date('dmY'); if($cache-&gt;has($cacheKey)) { $dailyPick = $cache-&gt;get($cacheKey); } else { // hit database $dailyPick = $cache-&gt;save($cacheKey); } </code></pre> <p>However, it gets me a mistake that I'm using the 'has' function on a non-object.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload