Solved

Need help with $wpdb->update

Posted on 2011-09-08
4
658 Views
Last Modified: 2012-05-12
I need to increment, by 1, the numbers in two different fields of a table I have in my wordpress database.

I'm not sure how to use $wpdb->update

I'd like to do something like this -

In table 'adshare', increase the counts in fields 'overall' and 'auth_count' by 1, where field 'author' = chris

My attempt (doesn't work)

$wpdb->update( 'adshare', "overall = overall+1, auth_count = auth_count+1","author = 'chris'");

Of course, the 'overall = overall+1' is based on mysql_query("UPDATE share SET....   and this 'update' thing in wp might not do that. Do I need to get the value of 'overall' first, then add the 1, then update?  I'm trying to keep this as efficient as possible, and that would add connections.
0
Comment
Question by:St_Aug_Beach_Bum
  • 3
4 Comments
 
LVL 7

Assisted Solution

by:boon86
boon86 earned 500 total points
Comment Utility
can you paste full code of your php with its query so that we can see what can we do here?
0
 

Author Comment

by:St_Aug_Beach_Bum
Comment Utility
That's pretty much it, it uses the wpdb function in wordpress, here: http://codex.wordpress.org/Class_Reference/wpdb

I can pull data out of the database like this:

----------------
$test=$wpdb->get_var("SELECT auth_count FROM adshare WHERE author = 'chris'");
echo $test;
---------------

Just don't know how to update/increment like I am trying to do.
0
 

Accepted Solution

by:
St_Aug_Beach_Bum earned 0 total points
Comment Utility
Ok, I've got it figured out :)

$wpdb->query("UPDATE adshare SET overall = overall+1 , auth_count = auth_count+1 WHERE author = '$author'");
0
 

Author Closing Comment

by:St_Aug_Beach_Bum
Comment Utility
Thanks for your help
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The viewer will learn how to count occurrences of each item in an array.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now