Julian Posted May 4, 2009 Share Posted May 4, 2009 Hi guys... I'm having this situation: SELECT * FROM pages WHERE status = '1' AND '$colname_page' IN (id_page) ORDER BY orden ASC `id_page` stored data is like (1,5,7,9). I need to "explode" the field and obtain only "$colname_page" in my results. Is there any way to do that? Thanks. e.g. $colname_page = 5 (I obtain only the records that have 5 on the `id_page` field.) Link to comment https://forums.phpfreaks.com/topic/156791-mysql-in-command/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Looks like poor DB design to me. I don't think MySQL has a function to explode or split a string. Link to comment https://forums.phpfreaks.com/topic/156791-mysql-in-command/#findComment-825717 Share on other sites More sharing options...
revraz Posted May 4, 2009 Share Posted May 4, 2009 I guess I don't understand your question, if you only want column 5, why are you even using IN? Link to comment https://forums.phpfreaks.com/topic/156791-mysql-in-command/#findComment-825774 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 You should never store comma separated values in one record. You should have a separate table to handle this. That way you don't run into this problem, and your database will be a little more normalized. Like Ken mentioned, there is no equivalent of explode in PHP in MySQL, AFAIK. You may be able to use REGEXP and match on 5, but I don't this would be the best approach. (Note: this does not take into account spacing) AND id_page REGEXP '(^5,|,5,|,5$)' Link to comment https://forums.phpfreaks.com/topic/156791-mysql-in-command/#findComment-825847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.