PHP, MSSQL, and JSON

I’m having problems with enabling the sort functions of jqgrid. I think I’ve narrowed the problem down to the way MSSQL is returning the data to the SQL query.

In an effort to troubleshoot, I’ve drastically simplified the problem. The query I’m using is below.

SELECT * FROM dbo.test ORDER BY locationName

When I run the query directly in MSSQL Management Studio, the top 5 ID entries are 132, 1309, 1295, 1281, 1267.

When I run the corresponding code in PHP, the top 5 ID entries are 1266, 1267, 1268, 1269, 1270 - it seems to be ignoring my order by clause. Is there something I need to do to force it to honor the ORDER BY locationName?

[php]$kpiQuery = “SELECT * FROM dbo.test ORDER BY locationName”;
$result = mssql_query($kpiQuery);
while($kpiRow = mssql_fetch_array($kpiResult)) {
echo $kpiRow[plDataID]."
";
}
[/php]

I’m curious about the order in management studio as it jumps from 132 then the higher number and descends… Meanwhile php is ascending after skipping 132? I’m gonna take a guess that the 132 is a typo and missing the last # and what your trying to do is: “SELECT * FROM dbo.test ORDER BY locationname DESC”

If that’s not it it may be kpirow is fetching from kpiresult but this query is just result so you may actually be calling a query from elsewhere in your code…

Sponsor our Newsletter | Privacy Policy | Terms of Service