Jump to content

Help sorting MS SQL database results


wake

Recommended Posts

I am trying to sort the results of a stored procedure, but am not having much luck. I want to be able to give sort options to the users.

Any help would be greatly appreciated.

 

I have the code below but can't seem to merge the two ideas.

 

$data = mssql_fetch_array($result);

foreach ($data as $key => $value) {

    $Title[$key] = $value['Title'];

}

array_multisort($Title, SORT_ASC, $data);

 

while($row = mssql_fetch_array($result)) {

    //echo sorted results here

}

 

Thanks in advance!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/118858-help-sorting-ms-sql-database-results/
Share on other sites

Maybe instead of:

 

while($row = mssql_fetch_array($result)) {

    //echo sorted results here

}

 

I need to iterate through the sorted array?

 

Still having issues with this...there has to be a way to do this other than an ORDER BY sql statement doesnt there?

 

 

Cant you do it in the Sql query?

 

For instance in MySQL you can do summat like " SELECT foo FROM bar ORDER BY something desc; "

 

I suppose you can then give users a drop down box that sends the php script a var that you can use to build your query?

 

Ie: if dropdown box = 1 the $blaa = " query type 1 "  ?

 

The results are fetched from a stored procedure, and I need to sort the results differently based on a category selected.

Not sure how to append an ORDER BY statement to a stored procedure, maybe this is possible?

 

Any other ideas?

 

 

Thanks for the input.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.