Solved

Need help with $wpdb->update

Posted on 2011-09-08
4
718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

733 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