Solved

Need help with $wpdb->update

Posted on 2011-09-08
4
690 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
ID: 36508771
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
ID: 36510805
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
ID: 36511420
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
ID: 36534725
Thanks for your help
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

810 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