Solved

Need help with $wpdb->update

Posted on 2011-09-08
4
742 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

687 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