comma - MySQL LIKE gives wrong result -
i want create blog , create 2 tables.
id name of category
i create article table.
id category_id article
i add each article multiple categories , save id comma separated values in category_id field. i.e.
id category_id article 1 1,2,3 xyz 2 1,5 ghjy.............. 3 2,4,6 hgyr..............
now wish post articles on category page.
$query = "select * article_table category_id '%category_id%' order id desc";
in above query till there 2 equal looking categories. articles of category 20,21,22,23 etc appear on category page of 2. how avoid this. '%--%' causing problem.
my question : wish show articles of different categories on different pages dynamically.
can ???
if using mysql, can use find_in_set function see if category wish find exists
try:
select * article_table find_in_set('searchforid', category_id) > 0 order id desc;
where 'searchforid' replaced category id you're looking for
Comments
Post a Comment