[eluser]Nick_MyShuitings[/eluser]
If you want to make your life a lot simpler, use a joining table for that many to many relationship:
table - categori_articol
fields - id, categori_id, articol_id
Then your sql is one query on the joining table to get the categories that are present, group_by categori_id and game over.
That said, if you want to continue with your existing table structure I'd propose this:
1) select count(categori);
2) select categoriemultipla from articol
Code:
$count = $this->db->count_all('categorie');
do {
$articols = $this->db->select('categoriemultipla')->get('articol')->result();
foreach($articols as $articol) {
$categori = explode(',',$articol->categoriemultipla);
foreach($categori as $categori_id) {
$categories[$categori_id] = $categori_id;
}
}
$newcount = count($categories);
} while ($newcount < $count);
var_dump($categories);
Should contain all the categories that have a linked article... and the good part is it will stop all the looping over the articles once it has found at least one that is in the category. Of course if you wanted something different like the number of articles in the category you would modify the logic a bit.