You are here:  » Re-order Featured Products

Support Forum



Re-order Featured Products

Submitted by paddyman on Fri, 2007-09-21 16:31 in

Hi David,

Is there any way to reorder the featured products, listing them in the order they are entered in the admin form rather than displaying them alphabetically. I presume this is done in index.php. Tried replacing group by name with group by sequence but this doesn't work.

Also, is it possible to place a number before the featured products. I'm only displaying the name of the product with a link. Would like to use a 2 column layout as follows. Have 1 column working with product at the moment.

<table cellspacing='0'>
   <?php foreach($featured["products"] as $product): ?>
    <tr>
      <td width="120" align='left'>1.</td>
        <td width="120" align='left'>
          <a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a> </td>
    </tr>
      <?php endforeach; ?>
  </table>

How would I get 2 to appear on the next row and so on?

Thanks

Paddyman

Submitted by support on Fri, 2007-09-21 16:45

Hi,

I'm not sure why the feature products are not being selected in sequence order if "ORDER BY sequence" is on the end of the query...The default code in index.php is as follows:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";

Check that this is the same as you are using. In order to make your number increment each time, that can be done with a counter variable. Try something like this:

<table cellspacing='0'>
   <?php $i 1?>
   <?php foreach($featured["products"] as $product): ?>
    <tr>
      <td width="120" align='left'><?php print $i."."$i++; ?></td>
        <td width="120" align='left'>
          <a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a> </td>
    </tr>
      <?php endforeach; ?>
  </table>

Hope this helps!
Cheers,
David.

Submitted by paddyman on Sun, 2007-09-23 17:33

Hi David,

Thanks for the reply. Got the numbers thing to work but still having a problem with my featured products displaying by name rather than by sequence. My code looks ok but there must be something amiss. I have sent you on an email with my index.php if you wouldn't mind taking a look.

Thanks

Paddman

Submitted by LauraH on Sat, 2008-02-09 21:42

Hi David, did you ever find a resolution to this problem as I'm struggling with the same thing?

Thanks for your help :o)
Laura

Submitted by support on Sun, 2008-02-10 19:49

Hi Laura,

Yes there is a fix for this situation. In index.php look for the following block of code that constructs the SQL to select the products after reading the featured products table:

    $sqlNames = array();
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
    }
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";

Replace this with the following new version, which adds a CASE statement to the SQL in order to force the sort to the sequence value from the featured products table:

    $sqlNames = array();
    $sqlCase = "CASE name";
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
      $sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN '".$featured["sequence"]."' ";
    }
    $sqlCase .= "END as sequence";
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants,".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name ORDER BY sequence";

If you're note sure where to make the changes, feel free to email me a copy of your index.php (reply to youre reg code or forum registration email) and and i'll add the changes for you.

Cheers,
David.