mysql php
数据库表结构将 1,3,4 分割成数组,然后遍历查询。
你这个要求有几个问题,首先说明数据库表设计的完全不对,要是查询出的结果还要拆分,拆完了还要like的查询那么就应该重新设计这个表,比如一行只记一个cids。
如果你一定要进行现在这样的操作,我建议你分两步走,不然会非常难写,第一步先
select cids from product where productid = xxxx
select productid from product where ','+cids+',' like '%,1,%'unionselect productid from product where ','+cids+',' like '%,3,%'unionselect productid from product where ','+cids+',' like '%,4,%'
select productid, productnamefrom product where find_in_set((select cids from product where productid = '$productid'), cids)
请将 cids 两端的圆括号去掉
即形如 (1,3,4) 的改为形如 1,3,4 的
然后使用自连接,连接条件使用 find_in_set 函数计算
select T1.* from product T1, product T2 where find_in_set(T1.productid, T2.cids) and 2.productid=1
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号