mysql - How to use Distinct Function through PHP in displaying unique value -


how display distinct values through php - resultant output unique

the distinct function not having impact on line

#__new_categories.cat_name cat_name 

here complete code

    <?php     $db = jfactory::getdbo();     $query = $db->getquery(true);     $c = $item->prod_cat_id;      $query = "select   distinct  #__new_categories.cat_name cat_name    , #__new_categories.cat_parent cat_parent    , #__new_products.prod_name  prod_name  #__new_categories   inner join #__new_products on #__new_products.prod_cat_id = #__new_categories.id   #__new_products.prod_cat_id = $c";      $db->setquery($query);                                       $results = $db->loadobjectlist();       foreach($results $row){        echo $row->cat_name;     }      ?>  

when echoing in cat_name displaying similar values

honda honda honda honda honda honda

ford ford ford ford ford ford

how use distinct function in

echo $row->cat_name; 

the problem comes inner join.

you can query:

group #__new_categories.cat_name

or handle php, because break query:

$results = $db->loadobjectlist();   $uniquevalues = array(); foreach($results $row){     if (!isset($uniquevalues[$row->cat_name])) {         echo $row->cat_name;         $uniquevalues[$row->cat_name] = true;     } } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -