Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.