-1

I want to exclude company_id 18 from this code... Below code is currently working, but there is a problem only display the company those have rating. I want to exclude some companies from this list.

<?php 
    //$selCompanyNav2 = mysql_query("select * from tbl_company WHERE status = 'Y' ORDER BY ordering ASC");
    $selCompanyNav2 = mysql_query("SELECT c.*,r.`term_id`,avg( r.post_rate_value ) AS rate_value  FROM tbl_company AS c 
                                    INNER JOIN tbl_rating AS r 
                                    INNER JOIN clewin_posts AS p ON r.`term_id`=c.`term_id` AND r.post_ID=p.ID AND p.post_status='publish' 
                                    GROUP BY r.term_id  ORDER BY rate_value DESC ");
    $num_resultsNav2= @mysql_num_rows($selCompanyNav2);
    if($num_resultsNav2>0){
?>

<ul>
    <?php   
    while($rowNav2 = mysql_fetch_assoc($selCompanyNav2)){  
        $titleNav2 =$rowNav2['company_name'];
        if($rowNav2['alttitle']){ $alttitle2=$rowNav2['alttitle'];}else{$alttitle2=$rowNav2['company_name'];}
        $company_seotitleNav2=$rowNav2['company_seotitle'];
        ?>
        <li>
        <a href="<?php bloginfo('wpurl'); ?>/window-companies/<?php echo $company_seotitleNav2;?>/" title=""><?php echo $titleNav2;?></a>
        </li>
    <?php } ?>
</ul>
<?php } ?>
Ajith
  • 2,476
  • 2
  • 17
  • 38
Shilpa
  • 21
  • 1
  • 4
  • 5
    *I want to exclude company_id 18 from this code...* Add `AND company_id != 18` to the query text. – Akina Jan 17 '20 at 05:56
  • I already tried this code. But not working – Shilpa Jan 17 '20 at 06:05
  • @Shilpa Can you check if any space exist in the database for company_id ' 18' also please confirm the datatype of company_id.. Alternate option is you can skip company_id = 18 in the loop – Ajith Jan 17 '20 at 06:09

1 Answers1

0

I got an answer.

The below code worked for me.

 $selCompanyNav2 = mysql_query(
   "SELECT c.*,r.`term_id`,AVG( r.post_rate_value ) AS rate_value  FROM tbl_company AS c 
    INNER JOIN tbl_rating AS r INNER JOIN clewin_posts AS p ON r.`term_id`=c.`term_id` 
    AND r.post_ID=p.ID 
    AND p.post_status='publish' 
    AND c.company_id NOT IN(14,15,16) 
    GROUP BY r.term_id  
    ORDER BY rate_value DESC "
);
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
Shilpa
  • 21
  • 1
  • 4