You are here:  » A to Z modification

Support Forum



A to Z modification

Submitted by DanielWestman on Tue, 2009-01-27 17:05 in

Hi,
As I won´t have thousands of products and only a few categories and brands, I would like to display categories, brands and merchants on the same page. I would like to display them as plain, single columns without the grouping by letter as the a to z is now. The columns should be in alphabetical order.

Is there an easy way to do this?

Best regards,
Daniel.

Submitted by support on Tue, 2009-01-27 17:46

Hi Daniel,

Probably easiest to do this in a self-contained script - have a go with this as a starting point...

all.php

<?php
  
require("includes/common.php");
  
$banner["h2"] = "<strong>All A-Z</strong>";
  require(
"html/header.php");
  require(
"html/menu.php");
  require(
"html/searchform.php");
  require(
"html/banner.php");
  print 
"<h3>Merchants</h3>";
  print 
"<ul>";
  
$sql "SELECT * FROM `".$config_databaseTablePrefix."feeds` ORDER BY merchant";
  if (
database_querySelect($sql,$rows))
  {
    foreach(
$rows as $feed)
    {
      if (
$config_useRewrite)
      {
        
$href $config_baseHREF."merchant/".tapestry_hyphenate($feed["merchant"])."/";
      }
      else
      {
        
$href $config_baseHREF."search.php?q=merchant:".urlencode($feed["merchant"]).":";
      }
      print 
"<li><a href='".$href."'>".$feed["merchant"]."</a></li>";
    }
  }
  print 
"</ul>";
  print 
"<h3>Categories</h3>";
  print 
"<ul>";
  
$sql "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
  if (
database_querySelect($sql,$rows))
  {
    foreach(
$rows as $product)
    {
      if (
$product["category"])
      {
        if (
$config_useRewrite)
        {
          
$href $config_baseHREF."category/".tapestry_hyphenate($product["category"])."/";
        }
        else
        {
          
$href $config_baseHREF."search.php?q=category:".urlencode($product["category"]).":";
        }
        print 
"<li><a href='".$href."'>".$product["category"]."</a></li>";
      }
    }
  }
  print 
"</ul>";
  print 
"<h3>Brands</h3>";
  print 
"<ul>";
  
$sql "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
  if (
database_querySelect($sql,$rows))
  {
    foreach(
$rows as $product)
    {
      if (
$product["brand"])
      {
        if (
$config_useRewrite)
        {
          
$href $config_baseHREF."brand/".tapestry_hyphenate($product["brand"])."/";
        }
        else
        {
          
$href $config_baseHREF."search.php?q=brand:".urlencode($product["brand"]).":";
        }
        print 
"<li><a href='".$href."'>".$product["brand"]."</a></li>";
      }
    }
  }
  print 
"</ul>";
  require(
"html/footer.php");
?>

Cheers,
David.

Submitted by DanielWestman on Tue, 2009-01-27 18:29

Thanks David, you read my mind!
This was exactly what I pictured.

Submitted by DanielWestman on Tue, 2009-01-27 19:10

Hi David,
I´ve added some extra fields that I would like to display in the same way, but when I for example replaced merchant in your code with one of my extra fields, type, I get this error:

[SELECT * FROM `feeds` ORDER BY type][Unknown column 'type' in 'order clause']
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\pt\includes\database.php on line 26

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\pt\includes\database.php on line 31

I´ve had some trouble with getting the extra fields into the database, but now it seems to work, I can check each individual value in phpMyAdmin, so I have no idea why this isn´t working.

Thankful for any help!
Daniel

Submitted by support on Tue, 2009-01-27 19:34

Hi Daniel,

Did you mean to select from the products table rather than feeds? In the all.php, only the merchants list uses the feeds table, the others (category and brand) use products...

Cheers,
David.

Submitted by DanielWestman on Tue, 2009-01-27 19:55

Ah, that was it, thanks! :)

Submitted by transparencia on Tue, 2010-11-02 02:11

Hi David!

What is the easisest way to know if the atoz.php script is showing categories and not products or brand? I want to show print only when it is showing categories.

Submitted by support on Tue, 2010-11-02 09:32

Hi,

If you want to add code to html/atoz.php only when a category index is being displayed, have a go with:

<?php if (strpos($_SERVER["PHP_SELF"],"categories.php")!== FALSE): ?>
<!-- HTML for categories page here -->
<?php endif; ?>

Cheers,
David.
--
PriceTapestry.com