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: [Jason] Sort Problem

By northernpenguin - May 10, 2010 - edited: May 10, 2010

Jason: I get a blank page when I make the changes you suggested.

I isolated it to the <?php echo $query> statement in the headings. This might be because I use a POST and not a GET for my query. Specifically, the original query is:

<form method="POST" action="specialResults.php">
<select name="cca" value="" size="1" style="width: 120px;">
<option value="" Select a CCA Report</option>
<?php foreach ($ccaRecords as $record): ?>
<option value="<?php echo $record['title'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach; ?>
</select>
<input type="submit" name="submit" value="Search">
<input type="reset" value="Reset">
</form>

Would that make a difference?
--
northernpenguin
Northern Penguin Technologies

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

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: [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