Sort Problem

10 posts by 2 authors in: Forums > CMS Builder
Last Post: May 10, 2010   (RSS)

Hi Everyone

I'm having a bit of a problem sorting columns in a table which is the output of a search. Instead of sorting on the search results, it sorts on the whole set of records. I used:

<a href="specialResults.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="course_id")? "course_id" : "course_id DESC" ?>">Course ID</a>
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Sort Problem

By Jason - May 10, 2010

Hi,

If you could attach specialResults.php, I can take a look at it for you.

Is there a link to this page so that I can see what it's doing?

Let me know.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Sort Problem

Jason: sorry, but the website is on a private network. Attached is the file.
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
Attachments:

specialresults.php 3K

Re: [northernpenguin] Sort Problem

By Jason - May 10, 2010

Hi,

The problem here is that the sorting link is wiping out all of the search parameters.

Above where your outputting your table headings, put in this code:

<?php $query="";
foreach($_REQUEST as $key=>$value){
if($key!="orderBy"){
$query.="$key=$value&";
}
}
?>


This will build a query string for us that has all of the search parameters the page is currently using (except for the orderBy variable.

Next, change our table headings like this:

<th><a href="specialResults.php?<?php echo $query ?>orderBy=<?php echo (@$_REQUEST['orderBy']!="course_id")? "course_id" : "course_id DESC" ?>">Course ID</a></th>
<th><a href="specialResults.php?<?php echo $query ?>orderBy=<?php echo (@$_REQUEST['orderBy']!="title")? "title" : "title DESC" ?>">Course Description</a></th>
<th><a href="specialResults.php?<?php echo $query ?>orderBy=<?php echo (@$_REQUEST['orderBy']!="approval_date")? "approval_date" : "approval_date DESC" ?>">Approval Date</a></th>


Give this a try and let me know if you run into any problems.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [northernpenguin] Sort Problem

By Jason - May 10, 2010

Is the page blank before you click on a sorting link, or only after?
Could you show me what the url looks like before and after you click on a sorting link?

Also, please reattach your .php file with the changes made so far.

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/

Re: [Jason] Sort Problem

Jason: attached are both the main file (index.php) and specialResults.php
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [Jason] Sort Problem

Jason: blanjk page is before trying to sort. Result of query. The URI output is http://cms-portal.halifax.mil.ca:8080/specialResults.php

If I change the POST to a GET, this is what I see: http://cms-portal.halifax.mil.ca:8080/specialResults.php?cca=CFNOS&submit=Search
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Sort Problem

By Jason - May 10, 2010

Hi,

There was a syntax error in your code. you were missing the "?" after you were outputting the $query variable. Replace your table headings output with this:

<th><a href="specialResults.php?<?php echo $query; ?>orderBy=<?php echo (@$_REQUEST['orderBy']!="course_id")? "course_id" : "course_id DESC" ?>">Course ID</a></th>
<th><a href="specialResults.php?<?php echo $query; ?>orderBy=<?php echo (@$_REQUEST['orderBy']!="title")? "title" : "title DESC" ?>">Course Description</a></th>
<th><a href="specialResults.php?<?php echo $query; ?>orderBy=<?php echo (@$_REQUEST['orderBy']!="approval_date")? "approval_date" : "approval_date DESC" ?>">Approval Date</a></th>


Give that a try and let me know if that works.

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/

Re: [Jason] Sort Problem

The simple things always get you!

Thanx Jason, you're a genius!
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke