You are here:  » ordering in the ascending order problem

Support Forum



ordering in the ascending order problem

Submitted by karakartal on Tue, 2010-10-19 02:29 in

Hi Dave,

I am having hard time figuring out this problem. I am attaching coupons and shipping costs and calculating bottomlineprice but when I sort them in the ascending order, the ordering comes up wrong. Can you please help me?

Here is an example page where the best bottomline price should be from Drugstore.com

{link saved}

This is the relevant part of my products.php

  if ($q)
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' LIMIT 1";
    database_querySelect($sql,$rows);
    if ($rows[0]["upc"])
    {
      $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($rows[0]["name"])."' OR upc = '".database_safe($rows[0]["upc"])."' ORDER BY bottomlineprice ASC LIMIT ".$config_resultsPerPage;
    }
    else
    {
      $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($rows[0]["name"])."' ORDER BY bottomlineprice ASC LIMIT ".$config_resultsPerPage;
    }
    $numRows = database_querySelect($sql,$rows);

Submitted by support on Tue, 2010-10-19 08:07

Hi,

It sounds like your bottomlineprice field is VARCHAR rather than a numeric type which would be required for the correct sort. Try the following dbmod.php script which convert the type to DECIMAL(10,2) which I think should fix it...

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            CHANGE `bottomlineprice` `bottomlineprice` DECIMAL(10,2) NOT NULL"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by karakartal on Wed, 2010-10-20 04:06

thanks. this fixes it.