You are here:  » Limit category

Support Forum



Limit category

Submitted by cq on Thu, 2009-06-18 08:35 in

Hi David,

For the below code, how can I limit the category to 10.

<?php
        $sql 
"SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
        if (
database_querySelect($sql,$rows))
        {
          foreach(
$rows as $row)
          {
            if (
$config_useRewrite)
            {
              
$href $config_baseHREF."category/".tapestry_hyphenate($row["category"])."/";
            }
            else
            {
              
$href $config_baseHREF."search.php?q=category:".urlencode($row["category"]).":";
            }
            print 
"<a href='".$href."'>".$row["category"]."</a><br />";
          }
        }
      
?>

thanks
jack

Submitted by support on Thu, 2009-06-18 08:38

Hello Jack,

Simply add LIMIT 10 to the end of the SQL, for example:

        $sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category LIMIT 10";

Cheers,
David.

Submitted by cq on Thu, 2009-06-18 08:43

Hi David,

Thank you very much. It works fine.

regards
Jack