 <p>In this code you always display your query (you have echo at the beginning).</p> <p>In my opinion there are only 2 options:</p> <ol> <li><p>You use some type of PHP cache. If you do, you probably won't see <code>SELECT MAX(version) as version FROM stats</code> every time you refresh the page</p></li> <li><p>You don't display $v value right after this code is being executed. <code>$v</code> variable is for example used often in loops so it's quite possible you change the value in some other part of your code and that's why it's always 10.</p></li> </ol> <p>So what you should do you should :</p> <pre><code>echo $sql = "SELECT MAX(version) as version FROM stats"; $result = mysql_query($sql); $rr=mysql_fetch_array($result); $v = $rr["version"]; echo $v; </code></pre> <p>And make sure you see messages each time you refresh your page. If it's not displayed it means you use cache, otherwise you should see correct value here.</p> <p>Of course, you also shouldn't use <code>mysql</code> functions any more because mysql extendsion is deprecated. You should use mysqli or PDO instead.</p>