开发者

MySQL Query: find the category id in the products table, however id is wrapped like `&12&`

I need to find the category id in the products table below. However the cms_ecom_cate开发者_如何学Pythongories.id is wrapped with the & character like &12&. Is there some kind of wild card I could use to wrap around? like %cms_ecom_categories.id% ?

 $sql = "SELECT * FROM cms_ecom_products, cms_ecom_categories 
         WHERE cms_ecom_products.pCategories = cms_ecom_categories.id
               AND cms_ecom_categories.slug = ".$page."";


You can use LIKE => WHERE id LIKE %12%

Or add the &-signs to the id: $page = '&' . $page . '&' => WHERE id = $page


  • Either use AND cms_ecom_categories.slug = '&".$page."&' - just put the ampersands in the quotes
  • Or use the _ wildcard, meaning exactly one character: AND cms_ecom_categories.slug LIKE '_".$page."_'
  • Or use the % wildcard, meaning zero or more characters: AND cms_ecom_categories.slug LIKE '%".$page."%'

It might be better to modify the $page variable itself though. And why are you building SQL-queries from a string? You should check parameterized queries or at least escape, it's easier and more secure.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜