This topic is locked
[SOLVED]

 ?orderby=dproperty_price

5/15/2010 3:35:39 PM
PHPRunner General questions
powersitedesign author

I have done this a thousand times w/ the old search functionality prior to v5.2 but w/ this new search implementation some of my links are not sorting correctly when I append ?orderby=dproperty_price at the end of them. Here is one example:
[*]Lakefront Listings
I have looked and looked and haven't been able to figure out what it might be. Here's how I have the URL structured, please tell me if this is not correct:

http://www.greersferrylake.net/cms/property_database_list.php?ctlSearchFor=&simpleSrchTypeComboNot=&a=integrated&id=1&criteria=and&type1=&value11=Lakefront+Homes&field1=property_category&option1=Equals&not1=&orderby=dproperty_price&pagesize=50"]http://www.greersferrylake.net/cms/property_database_list.php?ctlSearchFor=&simpleSrchTypeComboNot=&a=integrated&id=1&criteria=and&type1=&value11=Lakefront+Homes&field1=property_category&option1=Equals&not1=&orderby=dproperty_price&pagesize=50


Thanks for your help in advance,

J
Jane 5/18/2010

Cotton,
unfortunately simple orderby parameter in the URL won't be processed.

You need to click on the column header to sort records on the page or add ORDER BY statement to the SQL query manually.

Here is a sample "List page: Before SQL query" event:

if (@$_REQUEST["orderby"])

{

$order_field = GetFieldByGoodFieldName(substr($_REQUEST["orderby"], 1));

$order_dir = substr($_REQUEST["orderby"], 0, 1);

if($order_dir == "a")

{

$strOrderBy = " ORDER BY ".$order_field." ASC ";

}

else{

$strOrderBy = " ORDER BY ".$order_field." DESC ";

}
powersitedesign author 5/20/2010



Cotton,
unfortunately simple orderby parameter in the URL won't be processed.

You need to click on the column header to sort records on the page or add ORDER BY statement to the SQL query manually.

Here is a sample "List page: Before SQL query" event:

if (@$_REQUEST["orderby"])

{

$order_field = GetFieldByGoodFieldName(substr($_REQUEST["orderby"], 1));

$order_dir = substr($_REQUEST["orderby"], 0, 1);

if($order_dir == "a")

{

$strOrderBy = " ORDER BY ".$order_field." ASC ";

}

else{

$strOrderBy = " ORDER BY ".$order_field." DESC ";

}



Thanks Jane, I will give this a try. Thanks,

powersitedesign author 6/12/2010

I went in and added this to the List Page: Before SQL Query



// Place event code here.

// Use "Add Action" button to add code snippets.

if (@$_REQUEST["orderby"])

{

$order_field = property_price(substr($_REQUEST["orderby"], 1));

$order_dir = substr($_REQUEST["orderby"], 0, 1);

if($order_dir == "a")

{

$strOrderBy = " ORDER BY ".$order_field." ASC ";

}

else{

$strOrderBy = " ORDER BY ".$order_field." DESC ";

}


and I get this syntax error:

syntax error, '}' expected in line 16
Just to make sure I am in the correct screen, here is the screenshot:


I am sure it's something simple, can someone point me in the right direction?

Thanks for your help in advance.

Sergey Kornilov admin 6/14/2010

As error message say you are missing a closing curly brace at the end of this code snippet.

powersitedesign author 6/15/2010

Sergey -
I fixed the syntax error and the listings are still not sorting by property_price on the view page. Here's an example of a page not sorting correctly. I tried to upload this to the Demo account but it wouldn't let me? I am attaching the property_database_events.php file so you can see what I have in there. I am not for sure why this isn't wanting to sort by property_price. Any ideas?? I will keep trying to upload it to the demo account so you can see what I have.
Thanks in advance.

<?php
// List page: Before SQL query

function BeforeQueryList(&$strSQL,&$strWhereClause,&$strOrderBy)

{
// Place event code here.

// Use "Add Action" button to add code snippets.

if (@$_REQUEST["orderby"])

{

$order_field = property_price(substr($_REQUEST["orderby"], 1));

$order_dir = substr($_REQUEST["orderby"], 0, 1);

if($order_dir == "a")

{

$strOrderBy = " ORDER BY ".$order_field." ASC ";

}

else{

$strOrderBy = " ORDER BY ".$order_field." DESC ";

}

}

;

} // function BeforeQueryList

$arrEventTables["BeforeQueryList"]="property_database";
?>
powersitedesign author 6/15/2010

Sergey -
Something else, I can go to: http://www.greersferrylake.net/cms/property_database_list.php?orderby=dproperty_price (without specifying a category for a listing) and it sorts everything by price correctly, it's just when I add the rest of the URL to specify the category that it doesn't work.
Didn't know if that was useful or not, just wanted to let you know. Thanks, looking forward to hearing back from you.

powersitedesign author 6/16/2010

This is now resolved. I went into the database and noticed that the property_price field was inadvertantly set the varchar. I changed that and it immediately started working. Apparently that was the issue. I now have the script to validate currency for that field (which I should have done in the first place). Thanks for looking at it though, I am marking this issue closed but hopefully you can leave it in case someone else runs into this in the future.