[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Pages not sorting correctly on the new server.

Posted on 2007-08-06
13
Medium Priority
?
186 Views
Last Modified: 2008-01-09
Hello,
We have recently switched servers (due to the Valueweb SNAFU) and some of our pages are loading with the incorrect sorting.

We have one page that pulls data from MySQL and posts it on a page aphebetically.
This worked fine on the old server, but the new server doesn't sort it correctly, and none of the code has changed.

Is this a server setting I need to make somewhere?
0
Comment
Question by:CyberRazz32
  • 4
  • 4
  • 2
  • +2
13 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 19640994
I would start by looking at the php and mysql version on the different servers
0
 
LVL 9

Expert Comment

by:paradoxengine
ID: 19641000
Are you actually sorting them via an SQL ORDER BY or what?
0
 
LVL 4

Expert Comment

by:mpginsburg
ID: 19641010
Can you post the query that's running, and how the data looks on screen?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:hernst42
ID: 19641131
Check if the collation of mysql has been changed between both mysql-servers.
0
 

Author Comment

by:CyberRazz32
ID: 19641224
We lost everything on Valueweb (we can't even access the server) so I can't compare the versions.
But this is the code that worked on the old server, and now on the new server the sort doesn't work.
All of the values comeback correctly, just not sorted.

$sql = "SELECT * FROM `melody` WHERE `company` LIKE '$company' AND `make` LIKE '$make'AND `model` LIKE '$model' AND`type` LIKE '$type' AND `hulls` LIKE '$hulls' AND `cabins` >= '$cabins'  AND `cabins` <= '$maxcabins' AND `length` >= '$minlength' AND `length` <= '$maxlength' AND `heads` >= '$heads' AND `location` LIKE '$location'AND `ac` LIKE '$ac1'AND `cc` LIKE '$cc1' ORDER BY '$sort' ASC ";
      $result = mysql_query($sql);
      $nrows = mysql_num_rows($result);
      if($nrows != 0)
      {
echo "";


(etc......)
0
 
LVL 28

Expert Comment

by:gamebits
ID: 19641260
Check if the $sort variable in the query is being set.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 19641270
Shouldn't the order by in your sql be:
ORDER BY `$sort`
else you sort by a fixed string and not by a fieldname and thus the database will sort the rows different
0
 

Author Comment

by:CyberRazz32
ID: 19641275
It is,
Here is a better (easier to look at example), on the other page that isn't sorting:

$sql = "SELECT * FROM `crewedyachts` WHERE `type` LIKE 'sailboat' AND status NOT LIKE 'inactive' ORDER BY 'name' ASC ";
      $result = mysql_query($sql);
      $nrows = mysql_num_rows($result);
      if($nrows != 0)
      {
echo "";

The results come back, but not sorted (same code worked on the old server old MySQL, but not the new)
0
 
LVL 9

Expert Comment

by:paradoxengine
ID: 19641358
I agree, use an ORDER BY name query instead of ORDER BY 'name'.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 19641544
use ORDER BY `name` ASC  and not ORDER BY 'name' ASC  (note the backtick instead of the single quote. The single quote represents a string not a column and thus your example does not sort any way, as all rows have the same sort value "name" (as string)
0
 

Author Comment

by:CyberRazz32
ID: 19641854
Cool,
I will be testing this solution at 7pm tonight.  does the `` solution make sense on why it worked before and not now? If so i will be uploading this fix. Thanks
:)
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 19642133
if you used ' before it work accidentally. Yes it's good to use `if you use a reserved word as column you won't get sql-errors if you use `
0
 

Author Comment

by:CyberRazz32
ID: 19642309
you guys are GREAT!!
I changed the ' to ` and everything works.
Thank you!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question