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

  HighTower 14:27 11 Sep 06
Locked

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 06

something like:
$link_id=mysql_connect("$db_host","$db_user","$db_password");
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 06

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

  HighTower 20:53 13 Sep 06

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 06

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 06

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

  HighTower 18:47 16 Oct 06

harristweed,

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.

Nintendo Switch review: Hands-on with the intuitive modular console and its disappointing games…

1995-2015: How technology has changed the world in 20 years

Method Studios' title sequence for BBC series Taboo is truly unsettling

Best Pages for iOS tips | How to use Pages for iPad & iPhone: 6 simple tips to get more out of…