Jump to content

Display data that has been written to the database on the same page load


perky416

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.