Sort Problem
10 posts by 2 authors in: Forums > CMS Builder
Last Post: May 10, 2010 (RSS)
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
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
northernpenguin
Northern Penguin Technologies
"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
Re: [northernpenguin] Sort Problem
By Jason - May 10, 2010
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
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
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
northernpenguin
Northern Penguin Technologies
"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
Re: [Jason] Sort Problem
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
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
Thanx Jason, you're a genius!
northernpenguin
Northern Penguin Technologies
"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke