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 Link to comment https://forums.phpfreaks.com/topic/234282-display-data-that-has-been-written-to-the-database-on-the-same-page-load/ 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 Link to comment https://forums.phpfreaks.com/topic/234282-display-data-that-has-been-written-to-the-database-on-the-same-page-load/#findComment-1204105 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 Link to comment https://forums.phpfreaks.com/topic/234282-display-data-that-has-been-written-to-the-database-on-the-same-page-load/#findComment-1204108 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 Link to comment https://forums.phpfreaks.com/topic/234282-display-data-that-has-been-written-to-the-database-on-the-same-page-load/#findComment-1204110 Share on other sites More sharing options...
perky416 Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks mate, spot on Link to comment https://forums.phpfreaks.com/topic/234282-display-data-that-has-been-written-to-the-database-on-the-same-page-load/#findComment-1204136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.