Live Product List Ordering Question
14 posts by 3 authors in: Forums > CMS Builder
Last Post: July 5, 2012 (RSS)
By mark99 - June 12, 2012
1. I like to generate "orderBy=" links on my public product list / index page and often use these as a method of allowing readers to sort the output by title or price. One annoying problem that I keep coming accross is that the system treats three figure values/prices like 100 differently from two figure ones like 30. So if I have 30.00 for one product and 100.00 for the other and try to sort by price then 100.00 never gets ordered correctly because of the extra figure. Any prices with two primary figures (before the decimal) are ordered correctly but a value with three or more seem to do their own thing.
I can get around this by converting all of the smallest prices to look like this 030.00 but that's very ugly and seems to cause some people confusion. Is there an easier way to solve this?
2. As above, I like to use "orderBy=" links. For example, at the top of one product list I have a line like this.
<a href="List.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="title")? "title" : "title+DESC" ?>"><b>ISP Name (Alphanumeric)</b></a>
<a href="List.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="sfbb_cheap_price")? "sfbb_cheap_price" : "sfbb_cheap_price+DESC" ?>"><b>Price</b></a>
<a href="List.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="sfbb_cheap_setup")? "sfbb_cheap_setup" : "sfbb_cheap_setup+DESC" ?>"><b>Setup Fee</b></a>
<a href="List.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="sfbb_cheap_dl_speed")? "sfbb_cheap_dl_speed" : "sfbb_cheap_dl_speed+DESC" ?>"><b>Download Speed</b></a>
This works pretty much as I want it too, except I want the last option "sfbb_cheap_dl_speed" to do something different and for the first click to order ASC and not DESC like the others (i.e. highest first). But when I change sfbb_cheap_dl_speed+DESC to sfbb_cheap_dl_speed+ASC it still lists by Descending order and not ASC. How to fix?
Re: [mark99] Live Product List Ordering Question
By mark99 - June 13, 2012
Re: [mark99] Live Product List Ordering Question
By robin - June 13, 2012
1.
You can use a sql trick to force mysql to sort by number by using an order by like this:
'orderBy' => "CAST(price as DECIMAL(10,2))"
2.
Could you post some more of the code you're using (or a link to the page)? That will let me see what's going on. From what I can see already, the sfbb_cheap_dl_speed link will sort ascending if it's not the current sort.
Hope that helps,
Robin
Programmer
interactivetools.com
Re: [robin] Live Product List Ordering Question
By mark99 - June 14, 2012
2. Sure and I'll cut out the non-relevant formatting stuff to keep it down.
<?php
require_once "system/lib/viewer_functions.php";
list($isp_listRecords, $isp_listMetaData) = getRecords(array(
'tableName' => 'isp_list',
'perPage' => '15',
'where' => " category LIKE '%Superfast Broadband%' ",
'loadCreatedBy' => false,
));
?>
<b>ORDER LIST BY:</b> <a href="ISP_List_Superfast_Broadband.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="title")? "title" : "title+DESC" ?>"><b>ISP Name (Alphanumeric)</b></a> | <a href="ISP_List_Superfast_Broadband.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="sfbb_cheap_price")? "sfbb_cheap_price" : "sfbb_cheap_price+DESC" ?>"><b>Price</b></a> | <a href="ISP_List_Superfast_Broadband.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="sfbb_cheap_setup")? "sfbb_cheap_setup" : "sfbb_cheap_setup+DESC" ?>"><b>Setup Fee</b></a> | <a href="ISP_List_Superfast_Broadband.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="sfbb_cheap_dl_speed")? "sfbb_cheap_dl_speed" : "sfbb_cheap_dl_speed+ASC" ?>"><b>Download Speed</b></a>
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<?php foreach ($isp_listRecords as $record): ?>
<div id="ispsearch_title" style="float:left;"><a href="ISP_Detail_Superfast_Broadband.php?<?php echo preg_replace("/[ ]/", "-", $record['title']); ?>-<?php echo $record['num'] ?>" class="italhead"><b><?php echo $record['title'] ?></b></a></div>
<div style="float:right;padding-top:18px;margin-right:11px;"></div>
<div id="ispsearch_separate" style="clear:both;"></div>
<div id="ispsearch_box" style="width:125px;margin-left:10px;"><div id="ispsearch_boxhead"><b>Package Type</b></div>Cheapest <a href="http:/ISP_List_Fixed_Line_Broadband.php#info" title="The cheapest price package excludes special offer discounts that apply for less than 6 months">*</a></div>
<div id="ispsearch_box" style="width:90px;"><div id="ispsearch_boxhead"><b>Price</b></div>£<?php echo $record['sfbb_cheap_price'] ?></div>
<div id="ispsearch_box" style="width:90px;"><div id="ispsearch_boxhead"><b>Setup</b></div>£<?php echo $record['sfbb_cheap_setup'] ?></div>
<div id="ispsearch_box" style="width:90px;"><div id="ispsearch_boxhead"><b>Speed (DL)</b></div><?php echo $record['sfbb_cheap_dl_speed'] ?></div>
<div id="ispsearch_box" style="width:90px;"><div id="ispsearch_boxhead"><b>Speed (UL)</b></div><?php echo $record['sfbb_cheap_up_speed'] ?></div>
<div id="ispsearch_box" style="width:195px;"><div id="ispsearch_boxhead"><b>Monthly Data Usage</b></div><?php echo $record['sfbb_cheap_peak'] ?></div>
<div id="ispsearch_box" style="width:90px;"><div id="ispsearch_boxhead"><b>Hardware</b></div><?php echo $record['sfbb_cheap_hardware'] ?></div>
<div id="ispsearch_box" style="width:81px;"><div id="ispsearch_boxhead"><b>Contract</b></div><?php echo $record['sfbb_cheap_contract'] ?></div>
<div style="clear:both;"></div>
<div id="ispsearch_separate"></div>
<br />
<?php endforeach ?>
<?php if (!$isp_listRecords): ?>
<br /><br /><b><u>No records were found!</u></b><br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
Re: [mark99] Live Product List Ordering Question
By robin - June 15, 2012
1. Intercepting the orderBy might help keep things working as is. Something like:
$orderBy = @$_REQUEST['orderBy'];
if($orderBy=="sfbb_cheap_price") {
$orderBy = "CAST(sfbb_cheap_priceas DECIMAL(10,2))"
}
list($isp_listRecords, $isp_listMetaData) = getRecords(array(
'tableName' => 'isp_list',
'perPage' => '15',
'where' => " category LIKE '%Superfast Broadband%' ",
'orderBy' => $orderBy
'loadCreatedBy' => false,
));
2. It looks like "sfbb_cheap_dl_speed" order by link will sort ascending in any case. Since ASC is implied if no ASC/DESC is stated. Did you want it to sort descending on first click?
Hope that helps,
Robin
Programmer
interactivetools.com
Re: [robin] Live Product List Ordering Question
By mark99 - June 16, 2012 - edited: June 16, 2012
if($orderBy=="sfbb_cheap_price") {
$orderBy = "CAST(sfbb_cheap_price as DECIMAL(10,2))"
}
2. Yes I want it to sort ASC on the first click, but without damaging the DESC nature of the other links. That's the problem.
Re: [mark99] Live Product List Ordering Question
By robin - June 18, 2012
1. Ah line two is missing a semi-colon. Sometimes the compiler in my head isn't perfect. =)
2. I don't think you have a problem. The other links will remain DESC no matter what you change the sfbb_cheap_dl_speed link to.
Hope that helps,
Robin
Programmer
interactivetools.com
Re: [robin] Live Product List Ordering Question
By mark99 - June 28, 2012
1. Unfortunately as soon as I add that code in it messes up the general alphabetic list ordering, though I'm not quite sure why. It must somehow overide A-Z ordering just by existing. Any ideas?
Re: [mark99] Live Product List Ordering Question
By Jason - July 2, 2012
If you would like to send in a [url http://www.interactivetools.com/support]2nd Level Support [/url] Request, we can take a quick look and let you know what we find.
Thanks
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/