Jump to content

PHP MySql COUNT problem....


StefanRSA

Recommended Posts

I have ads from diff categories. Each ad is under a subcat and each subcat have a number of fields that contain data that I want to make search able. My script works fine, but when I try to use count the result is not correct???

Why not?

 

My Code:

$links = mysql_query("SELECT 
            adsubcat.id, ads.subcatid AS subid, adcat.id, ads.catid, COUNT(adcat.name), adcat.name, adsubcat.ads,
            adcat.catcol1, adcat.catcol2, adfields.f_value AS fieldvalue
          FROM ads
          JOIN adfields ON adfields.ad_id=ads.id
            JOIN adsubcat ON adsubcat.id=ads.subcatid
            JOIN adcat ON adcat.id=ads.catid
            WHERE MATCH (text, adfields.f_value) AGAINST ('%$searchword%' IN BOOLEAN MODE) GROUP BY ads.catid") or died("Record NOT Found");
            while($rows = mysql_fetch_array($links)){
$catbg=$rows['catcol1'];
$cathover=$rows['catcol2'];
$cat_idA = $rows['id'];
$cat_name = $rows['name'];
$tot_ads = $rows['COUNT(adcat.name)'];
$cat_desc = $rows['description'];

echo '<a class="menuitem'.$cat_idA.'" href="'.$root.'/catsearch/'.$cat_idA.'/'.$searchword.'" >'.$cat_name.' ('.$tot_ads.')</a>';
    }

 

This prints out the correct cats that contain the $searchword I search for but the total results that $tot_ads is printing is completely wrong...

 

Please help

Link to comment
https://forums.phpfreaks.com/topic/189351-php-mysql-count-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.