PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

LIKE query

s2Member Plugin. A Membership plugin for WordPress®.

LIKE query

Postby epixmedia » November 29th, 2011, 8:17 am

Hi all, I'm using the following query to perform a search on the member database, specifically the custom s2member fields.


$users = $wpdb->get_results ("SELECT `user_id` as `ID` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "s2member_custom_fields' AND `meta_value` REGEXP '.*\"".$searchfield."\";s:[0-9]+:\"".$searchvar."\".*'");


How do I alter this so it looks for matches LIKE the $searchvar instead of exact matches? for example, in regular SQL it would be, ...where $searchfield LIKE '%$searchvar%' so "epix" would match "epix media" or "somethnig epix something" for example...

Thank you :)

Zoe
Last edited by epixmedia on December 1st, 2011, 3:15 am, edited 1 time in total.
User avatar
epixmedia
Registered User
Registered User
 
Posts: 59
Joined: November 15, 2011

Re: LIKE query

Postby epixmedia » December 1st, 2011, 3:15 am

Is anyone able to help me on this? I need to be able to search for non-exact results...

Cheers,

Zoe
User avatar
epixmedia
Registered User
Registered User
 
Posts: 59
Joined: November 15, 2011

Re: LIKE query

Postby Cristián Lávaque » December 2nd, 2011, 3:11 am

These references may help:

http://dev.mysql.com/doc/refman/5.0/en/regexp.html
http://dev.mysql.com/doc/refman/5.0/en/ ... ching.html

I haven't used regex in queries yet, so I had to look them up, I'm familiar with PHP ones.

I haven't tested this, but you could try .* before and after the $searchvar:

'.*\"" . $searchfield . "\";s:[0-9]+:\".*" . $searchvar . ".*\".*'

I hope it helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: LIKE query

Postby epixmedia » December 2nd, 2011, 4:04 am

Cheers Cristian, I'll give it a try and let you know the results!!
User avatar
epixmedia
Registered User
Registered User
 
Posts: 59
Joined: November 15, 2011

Re: LIKE query

Postby epixmedia » December 2nd, 2011, 4:11 am

hmm, no luck yet. Jason helped me with the original code to get the search to work - if he's about could you see if perhaps he has time to look at this thread please?

In the meantime I will continue to Google!

Thanks,

Zoe
User avatar
epixmedia
Registered User
Registered User
 
Posts: 59
Joined: November 15, 2011

Re: LIKE query

Postby epixmedia » December 2nd, 2011, 4:19 am

Scratch that! It does work - it was a different part of my code that's not working! Thanks Cristian - much appreciated!
User avatar
epixmedia
Registered User
Registered User
 
Posts: 59
Joined: November 15, 2011

Re: LIKE query

Postby Cristián Lávaque » December 4th, 2011, 3:27 am

Excellent! :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 2 guests

cron