2

I have this table where in it store the score and based on each category. The data store in this format, "_bestscore_category1_user1", the title of the stats, the name of the category, and the user. As you can see they are delimited by underscore.

Table
---------------------------------------- 
User                       | Score
_bestscore_category1_user1 |  10
_bestscore_category1_user2 |  20
_bestscore_category2_user2 |  20
_bestscore_category2_user1 |  5 

So the problem is that, Im trying to query the field based on the user, my sql statement is like this.

SELECT meta_value from wp_postmeta WHERE meta_key REGEXP '_bestscore_([^=])_". $user."'

As you can see we have variable $user which is dynamic, trying this sql, gives me a null output. I wonder if my sql is incorrect, I did try to validate it, but null is the value I'm getting. Any idea?

Note: SQL statement, is not related to the table,

1
  • Try changing the regex to _bestscore_([^_]*)_ Commented Nov 21, 2014 at 4:17

1 Answer 1

1

Try this:

SELECT meta_value from wp_postmeta WHERE meta_key REGEXP '_bestscore_.*?_". $user."'

this will solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.