You are here:  » Page Layout

Support Forum



Page Layout

Submitted by andben on Thu, 2011-05-26 02:04 in

Hi David,
can you tell me please if is possible to adapt the code on this thread http://www.pricetapestry.com/node/2014 to have a "ul" - "/ul" tag closing and opening every 10 rows, similar to this modification: http://www.pricetapestry.com/node/284
Regards,
Andrea

Submitted by support on Thu, 2011-05-26 08:08

Hi Andrea,

No problem - here's a version of that mod with the </ul><ul> every 10 rows, with the number of rows set in a variable at the first line;

<?php
  $numRows 
10;
  print 
"<h4>Categories</h4>";
  
$sql "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
  if (
database_querySelect($sql,$rows))
  {
    
$i 0;
    print 
"<ul>";
    foreach(
$rows as $row)
    {
      print 
"<li><a href='".$config_baseHREF."search.php?q=brand:".$row["category"]."'>".$row["category"]."</a></li>";
      
$i++;
      if (
$i==$numRows)
      {
        print 
"</ul><ul>";
        
$i 0;
      }
    }
    print 
"</ul>";
  }
  print 
"<h4>Brands</h4>";
  
$sql "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
  if (
database_querySelect($sql,$rows))
  {
    
$i 0;
    print 
"<ul>";
    foreach(
$rows as $row)
    {
      print 
"<li><a href='".$config_baseHREF."search.php?q=brand:".$row["brand"]."'>".$row["brand"]."</a></li>";
      
$i++;
      if (
$i==$numRows)
      {
        print 
"</ul><ul>";
        
$i 0;
      }
    }
    print 
"</ul>";
  }
  print 
"<h4>Merchants</h4>";
  
$sql "SELECT DISTINCT(merchant) as merchant FROM `".$config_databaseTablePrefix."products` ORDER BY merchant";
  if (
database_querySelect($sql,$rows))
  {
    
$i 0;
    print 
"<ul>";
    foreach(
$rows as $row)
    {
      print 
"<li><a href='".$config_baseHREF."search.php?q=merchant:".$row["merchant"]."'>".$row["merchant"]."</a></li>";
      
$i++;
      if (
$i==$numRows)
      {
        print 
"</ul><ul>";
        
$i 0;
      }
    }
    print 
"</ul>";
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by andben on Fri, 2011-05-27 10:06

Hi David,

thanks for the new version; only one problem with the loop, I cannot have more than 1 time the tags closing.
Regards, Andrea

Submitted by support on Fri, 2011-05-27 10:56

Hi Andrea,

Sorry about that - I missed the code to reset $i to zero after each loop - corrected above...

Cheers,
David.
--
PriceTapestry.com

Submitted by andben on Fri, 2011-05-27 12:28

Thank you David