Why not SUBSTRING()
? I think it would be faster anyway:
SUBSTRING(project_num, 1, 2) = '$qmonth'
题
SELECT * FROM table WHERE sid=$steering_committee AND project_num = REGEX '/^$qmonth/'");
project_num is an 11 char string with the month being the first 2 chars. I want to filter based on the $month passed from form input and display.
I've also tried this:
SELECT * FROM table WHERE sid=$steering_committee AND project_num = REGEXP '^[" . $qmonth . "]'");
doesn't like syntax on this either
没有正确的解决方案
其他提示
Why not SUBSTRING()
? I think it would be faster anyway:
SUBSTRING(project_num, 1, 2) = '$qmonth'
Try this instead:
SELECT * FROM table WHERE sid=$steering_committee AND project_num REGEXP '^$qmonth'
Then ask your self a few questions.
Should I be using prepared statements instead of variable interpolation? Or, do I just like being hacked?
Should I really be using a REGEXP, which can never be indexed, or would a very indexable prefix match work just as well "AND project_num LIKE '$qmonth%'"? Or do you really dislike snappy web pages?