php - Show names from comma seperated values -


i have query on article data contains mysql column called products. field contains values 2,20,12. numbers represent id's of rows of products associated article.

i need work out how can display products under each article without creating duplicates of each result.

     $sql5="select * #__content catid=$iconcategoryid";      $db->setquery($sql5);      $articles= $db->loadobjectlist();      foreach($articles $article){           $product_ideez = $article->products;          $sql6="select * #__products_products id in($product_ideez)";         $db->setquery($sql6);         $products= $db->loadobjectlist();          foreach ($products $product) {          $productarray .= '<span class="badge">'.$product->name.'</span>';          }        // html output here     // getting duplication on output of product names      echo '<h1>'.$article->title.'</h1>';     echo '<hr/>';     echo $productarray; // works multiplied each new entry against first query.     } 

i hope question clear enough.

http://imgur.com/e0btluo

cheers john

you need initialize $productarray before using. add beginning of first foreach:

$productarray = ""; 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -