perky416 Posted April 20, 2011 Share Posted April 20, 2011 Hi guys, Should be a simple 1. If i have the following at the top of the page: $page_views = $row['page_views'] + 1; mysql_query("UPDATE table SET page_views='$page_views'"); and then the following at the bottom of the page: echo $row['page_views']; Should I see the page views as 1 the first time the page is visited, 2 the second time the page is visited, and so on......? At the moment im seeing 0 on the first page visit, 1 on the second page visit, 2 on the third..... I had this problem before on another page i was working, and i simply solved it by displaying the mysql query above the echo similar to the code above. However now it does not seem to be working. Am i missing something really simple? lol Thanks Quote Link to comment Share on other sites More sharing options...
spiderwell Posted April 20, 2011 Share Posted April 20, 2011 why not just echo out $page_views instead Quote Link to comment Share on other sites More sharing options...
perky416 Posted April 20, 2011 Author Share Posted April 20, 2011 Hi Spiderwell, That was just a quick example that I knocked up on my site of writing to a database and displaying the updated data on the same page load. Im trying to figure out how it works. I thought that by placing the code that writes to the database before the echo, it would be updated before the value is displayed. Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
spiderwell Posted April 20, 2011 Share Posted April 20, 2011 i think to get the new value after an UPDATE you will need to do a new SELECT. but i'm not 100% on that Quote Link to comment Share on other sites More sharing options...
perky416 Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks mate, spot on Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.