AviNahum Posted July 11, 2009 Share Posted July 11, 2009 hey, ummm i make an articles system, when i add a new article, i choose which categories i want to put in this article (i can choose more than one category)... when i insert the article into DB i just implode all checkboxes and insert it like this (1,4,6,3) each number is an category id... then i have to dispaly it on the index, the url is "index.php?cat=5" that mean we are looking for articles on category id 5... when i choose only 1 category for 1 article its simple, usually i using this "SELECT * FROM article WHERE category="$_GET['cat']".... but at this time i have to show each article in few categories and i have no idea how to select it... i tried this code but it's wont work (i lost my self into this code and i have no idea what i did here) public function cat($id) { global $cms, $DB; $DB->query("SELECT * FROM cms_articles"); $c = $DB->fetch_row(); foreach ($c as $a) { $cats = explode(',', $a['cats']); if (in_array($id, $cats)) { $DB->query("SELECT * FROM cms_articles WHERE id={$a['id']}"); $data = $DB->fetch_row(); } } return <<<EOF {$data['content']} EOF; } i need to show all article in this category if someone can explain me in simple words what i should to do i I'll thank him... i hope you understend what i trying to do cuz it's difficult to me to explain it in english Thanks! Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted July 11, 2009 Share Posted July 11, 2009 im guessing you mean if u tag an article for 'this' cat and 'that' cat, that u want it to show up in both. you could prolly use something like this: $id=$_GET['id']; $res=mysql_query("SELECT * FROM table WHERE `cat_id` LIKE '%$id,'"); lemme know Quote Link to comment Share on other sites More sharing options...
xtopolis Posted July 11, 2009 Share Posted July 11, 2009 You could concatenate the categories onto the url with a delimiter, and then explode them for the query and use IN() for the selection. Example, say these are checkboxes (name(value)) [] food(1) [] hiking(2) [] surfing(3) You would then get the values of all selected checkboxes, and concatenate them together. So if I selected food and surfing, and a delimiter of '|' I would have a string like: 1|3 which I could append to the url such as: yourpage.php?cat=1|3 (a better idea might be to do it with binary values so that you just send a single number) Anyway, on your page with the sql, you would explode on |, and make the query: SELECT * FROM cms_articles WHERE id IN (1,3) Quote Link to comment Share on other sites More sharing options...
AviNahum Posted July 11, 2009 Author Share Posted July 11, 2009 i want to arrange all article in list on categories they belong... in simple word, i need to select all article from DB and for each article i have to explode the categories and just check if this article belong to the category id that in the url (index.php?cat=5) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.