/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Need Help With Regular Expression in MySQL Query

This is my first time needing to use a regular expression in an MySQL statement. The following example is a WordPress database interaction. The focus though should be on the use of the regular expression in the query.

Here’s my attempt:

[code=php]

<?php

global $wpdb;

$rows = $wpdb->get_row(“SELECT * FROM $wpdb->bp_activity WHERE action REGEXP ‘(.*)^(http://sociallyaffluent.com/21andolder)(.*)$’ “, ARRAY_N);

if (isset($rows)) { echo ‘its set’; } else { echo ‘not set’; }

?>

[/code]

There’s nothing wrong with the rest of the code. It’s the regular expression. I’m feeling that this isn’t the proper way to use regexp in SQL statements. Any advice?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ChuckBauthorDec 23.2011 — Okay...it's solved..

I had a couple of issues: 1. My DB access was wrong and 2. You're suppose to use the "LIKE" sql command

[code=php]
<?php

global $wpdb;

$rows = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_url LIKE '%sociallyaffluent.com/21andolder%' ", ARRAY_N);

if (isset($rows)) { echo 'its set'; } else { echo 'not set'; }

?>
[/code]
×

Success!

Help @ChuckB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...