开发者

How would I use PHP substr?

I am trying to figure out how to use substr in my program to get the appropriate data from a table.

User picks 'Letters' "AA", "AB", "AC", "AD", "AE" or "all"

Then I need to compare if the 'panelID' has the 'Letters' I assume using substr.

panelID example: 1122AA-0010

$_SESSION['yield'] = "
from (select distinct panelID from DATABASE.TABLE) s, DATABASE.TABLE p
where p.panelID = s.panelID and p.laminationts > '$start_date' and p.laminationts < '$end_date'
group by week(p.laminationts)";

Something like this

"where substr(p.panelID,4,2) = substr(s.panelID,4,2) and p.laminationts > '$start_date' and p.lami开发者_Python百科nationts < ..."


Another option is to use the LIKE operator and % wildcard. It will find any rows that contain the string of text you are interested in:

http://socialstreams.co/40/MySQL_LIKE_Operator


You need substr(p.panelID,5,2), because the first character is at position 1, not 0.

Also, beware that using functions in WHERE clause avoids using any indexes on those fields. Maybe you could restructure your DB (for example split the panelID in multiple fields and create a composite PK on those fields) to allow the usage of indexes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜