Use UPDATE query in mysql to increase field by "1"

  HighTower 14:27 11 Sep 2006

I have written a content management system (DW8, PHP, mySQL) which allows a user to add, edit and remove content from a mySQL database using php pages. One of the many fields in the table which contains the main page content is a field called "hits". Another field is called "pdf" and contains a link to a specific pdf file for that record.

I want to be able to insert a link or button which when clicked or pressed updates the field "hits" by 1 and then takes the viewer to the pdf in the field "pdf".

Anyone any ideas? It's the updating the "hits" field by 1 part that I'm having bother with.

Thanks in advance.

  harristweed 14:51 11 Sep 2006

something like:
if (mysql_select_db("$db_database", $link_id));

mysql_query("UPDATE tablename SET hits=(hits + 1) WHERE row_identifier=$variable");

  HighTower 20:45 13 Sep 2006

I'll give it a bash and let you know how it goes. Thanks for your reply.

  HighTower 20:53 13 Sep 2006

Before I get stuck in where would I put this code in my page? Where would it need to go to be actioned by the hyperlink?

Thanks again, I see a light at the end of the tunnel!

  harristweed 09:45 14 Sep 2006

The code to update the hit counter needs to be actioned after the button/link is actioned. From what you say the link will interrogate the database to find the corresponding PDF file. The hit update will therefore be part of the code that does this operation.

  HighTower 11:20 18 Sep 2006

Cheers for that, I'll give it a go.

  HighTower 18:47 16 Oct 2006


Only just managed to find the time to try out your suggestion and after a little experimentation it does what I want it to do perfectly.

Thanks very much for you help (again!).

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Xiaomi Mi Mix 2 review

Halloween Photoshop & Illustrator tutorials: 20 step-by-step guides to creating spook-tacular…

iPhone X news: Release date, price, new features & specs

Comment créer, modifier et réinitialiser un compte Apple ?