I have a table wp_posts with a column post_content. some of the post entry has [nggallery id=x] inside post_content column. I want to find all the posts along with x (gallery id no, it is different for different gal开发者_如何学Golery) ascending which has nggallery id in post_content column. How can I do it?
You can try something like this:
SELECT * FROM wp_posts WHERE post_content LIKE '%[nggallery id=%';
Try this, just don't ask :)
select
left(substring(post_content,locate('[nggallery id=',post_content)+14,5),locate(']',substring(post_content,locate('[nggallery id=',post_content)+14,5))-1) as NumValue, post_content
from wp_posts
WHERE post_content LIKE "[nggallery id=%]"
ORDER BY 1
Maybe he meant this:
SELECT * FROM wp_posts WHERE post_content LIKE "[nggallery id=%]"
MySQL String Comparison Functions: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
精彩评论