You are here:  » Count Filters Problems


Count Filters Problems

Submitted by marco.saiu on Thu, 2018-01-18 13:30 in

Hello David,

i try to add count number in filter but not work.

Have any idea:

<?php
    if ($parts[0] != "tipo")
    {
          $sql1 = "SELECT tipo,COUNT(id) AS tipoCount FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." AND tipo <> '' GROUP BY tipo ORDER BY tipoCount DESC";
        if (database_querySelect($sql1,$rows1))
        {
          $newRows1 = array();
          foreach($rows1 as $row)
          {
            $tipos = explode(",",$row["tipo"]);
            foreach($tipos as $tipo)
            {
              $tipo = trim($tipo);
              if ($tipo)
              {
                $newRows1[$tipo]["tipo"] = $tipo;
              }
            }
          }
          ksort($newRows1);
          $rows1 = $newRows1;
          print "<h3>".translate("Tipo")."</h3>";
          print "<div class='content-accordion-filter'>";
          print "<input name='tipoFilter' value='' type='hidden'>";
          print "<ul class='list-submit'>";
          foreach($rows1 as $row)
          {
            print "<li><a class='link-list' data-value='" .htmlspecialchars($row["tipo"],ENT_QUOTES,$config_charset). "'>" .htmlspecialchars($row["tipo"],ENT_QUOTES,$config_charset). "</a> (".$row["tipoCount"].")</li>";
          }
          print "</ul><!--end list-submit-->";
          print "</div>";
        }
    }
?>

Thanks,
Marco Saiu

Submitted by support on Thu, 2018-01-18 13:39

Hello Marco,

Because you are using code to split comma separated values into individual options the tipoCount variable needs to be copied into $newRows1 so where you have this line:

                 $newRows1[$tipo]["tipo"] = $tipo;

...REPLACE with:

                 $newRows1[$tipo]["tipo"] = $tipo;
                 $newRows1[$tipo]["tipoCount"] = $row["tipoCount"];

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Thu, 2018-01-18 13:44

Thanks David now work.

Marco Saiu

Submitted by marco.saiu on Fri, 2018-01-19 13:40

Hello David,

i have issue with filters count. I think not is possible count on sql but i need count via php.

Query via sql:

Maglieria,Felpe 51836
Maglie,Maglieria 12665
Maglioni,Maglieria 5841
Maglieria,Cardigan 3390
Maglie,Maglieria,Felpe 1721
Maglioni,Maglie,Maglieria 1390
Maglieria 1003
Maglie,Maglieria,Cardigan 754
Maglieria,Gilet 736

Filter results:

Abiti (1)
Cardigan (3)
Dolcevita (1)
Felpe (2)
Gilet (1)
Maglie (1)
Maglieria (1)
Maglioni (1)

Have idea how to currect this filters:

{code saved}

Thanks,
Marco Saiu

Submitted by support on Fri, 2018-01-19 14:06

Hello Marco,

The filter selection SQL is restricted by the WHERE clause in effect for the corresponding search results:

$where.$priceWhere

If you try a search for "bw:" (without the quotes), that's the "Begins With" operator and with nothing after the ":" returns all products on your site so that might reveal the correlation with a raw SQL count...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Fri, 2018-01-19 14:14

Hello David,

i try but not work i think the problem is on the field, because have multiple value comma separated. I split this value with your php code and the count on sql not have utility.

Or not?

Thanks
Marco Saiu

Submitted by support on Fri, 2018-01-19 14:16

Hi Marco,

After applying a filter, is the number of results the same as shown in the brackets next to the filter option before submitting the form?

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Fri, 2018-01-19 14:20

Hello David,

with bw:

{code saved}

without bw:

{code saved}

Not have change any code on php file.

Thanks,
Marco Saiu

Submitted by support on Fri, 2018-01-19 15:52

Hi Marco,

How were the above lists created as they appear to be identical but breaking the field by every letter e.g.

w (1)
wi (1)
wid (1)
widg (1)
widge (1)
widget (1)

...but the filter selections from this comment look OK so I'm not sure where the problem lies - can you post the latest filter code again and I'll check it out further with you...

Thanks,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Fri, 2018-01-19 15:59

Hello David,

this problem depend of varchar on database i have fix this with change long of field from (64) to (600).

But the count on sql not count single value but only value with comma.

78848 Abiti
10770 Abiti,Giacche
2258 Abiti da cerimonia,Abiti
1190 Gonne classiche,Abiti,Gonne
1129 Abiti,Maglie,Maglieria
864 Abiti,Abiti da sposa
481 Abiti,Maglieria,Felpe
347 Abiti,T-shirts,Magliette e T-shirts,Top e Canotte
304 Abiti,Magliette e T-shirts,Top e Canotte
300 Abiti,Giacche,Abiti da sposa
245 Abiti,Camicie,Camiciette
229 Abiti,Copricostume
209 Abiti,Camicie,Tuniche e Caftani
189 Abiti,Maglioni,Maglie,Maglieria
180 Abiti,T-shirts,Magliette e T-shirts
166 Abiti,Camiciette,Camicie
166 Abiti,Giacche,Maglieria,Gilet
154 Abiti,Tuniche e Caftani,Camicie
134 Abiti,Giacche,Cappotti e Giacconi,Cappotti
133 Abiti,Maglioni,Maglieria
129 Abiti da cerimonia,Abiti,Giacche
123 Abiti da cerimonia,Abiti,Abiti da sposa

Thanks,
Marco Saiu

Submitted by marco.saiu on Fri, 2018-01-19 16:01

Abiti (1)
Abiti da cerimonia (1)
Abiti da sposa (1)
Bluse (1)
Camicie (1)
Camiciette (1)
Cappotti (1)
Cappotti e Giacconi (1)
Cardigan (1)
Copricostume (1)
Dolcevita (1)
Felpe (1)
Giacche (1)
Giacconi (1)
Gilet (1)
Giubbotti (1)
Gonne (1)
Gonne classiche (1)
Impermeabili (1)
Leggings e Fuseau (1)
Maglie (1)
Maglieria (1)
Magliette e T-shirts (1)
Maglioni (1)
Mantelle (1)
Minigonne (1)
Pantaloncini (1)
Pantaloni (1)
Pantaloni capri (3)
Pantaloni classici (1)
Pantaloni vita bassa (1)
Piumini (1)
Polo (1)
Salopette (1)
Stole (1)
T-shirts (1)
Top e Canotte (1)
Tuniche e Caftani (1)

This is value on filter...

Submitted by support on Sat, 2018-01-20 09:42

Hello Marco,

I just realised that the counts needs to be summed - so going back to the original filter code in the first post where you have this line:

  $newRows1[$tipo]["tipo"] = $tipo;

...REPLACE with:

  $newRows1[$tipo]["tipo"] = $tipo;
  if (!isset($newRows1[$tipo]["tipoCount"]))
  {
    $newRows1[$tipo]["tipoCount"] = $row["tipoCount"];
  }
  else
  {
    $newRows1[$tipo]["tipoCount"] += $row["tipoCount"];
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Sat, 2018-01-20 11:03

Hello David,

Yep work...

Thanks,
Marco Saiu