View Single Post
  #4 (permalink)  
Old Feb 3rd, 2008, 10:14
Rakuli's Avatar
Rakuli Rakuli is offline
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Adding 1 to Column Value

Umm... You're really overcomplicating the matter

You don't need to fetch anything from the database at all. You have the views with a default value of 0 so all you need to do is.

PHP: Select all



// Update the views

mysql_query("UPDATE content SET views = views+1 WHERE contentid=$contentid");

// Then retrieve the data 

$result mysql_query("SELECT views FROM content WHERE contentid=$contentid");

$row mysql_fetch_assoc($result);

// echo views before

echo $row['views']-1;

// echo views after

echo $row['views']; 

That will update it without having to bring PHP into the story at all MYSQL is much quicker than PHP so whenever you can use mysql's functions and logic, use it.
Reply With Quote