Jump to content

View index in descending order?


thetechgeek

Recommended Posts

Hey all,

I'm working with a mysql database and I need to be able to view the data in the database ordered by the index and in descending order. I can't seem to get the query correct, though. Whenever I do:

 

SELECT * FROM ShippingData ORDER BY Index DESC

 

 

I get the following error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Index DESC' at line 1

 

 

I also tried flipping the order of the data in the array containing it, but I get an error.

Attempt at making code to do that:

 

$order = mysql_real_escape_string($_POST["ord"]);
$aord = mysql_real_escape_string($_POST["aord"]);
$rev = false;

if ($order != "Index") {
  $query="SELECT * FROM ShippingData ORDER BY " . $order . " " . $aord;
} else {
  $query="SELECT * FROM ShippingData";
  if ($aord == "DESC") $rev = true;
}

$rt=mysql_query($query);
echo mysql_fetch_array($rt);
if ($rev) $rt = array_reverse($rt);  //Line 26
echo mysql_error();
while($nt=mysql_fetch_array($rt)){  //Line 28
...Snip...
echo "<tr><td>$nt[index]</td><td>...Snip...</td></tr>";
}

 

 

Output:

 

Array

Warning: array_reverse() [function.array-reverse]: The argument should be an array in /home/.kenmore/generalpersuasion/persuasionarmy.org/temple/shipping/scripts/view.php on line 26

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.kenmore/generalpersuasion/persuasionarmy.org/temple/shipping/scripts/view.php on line 28

 

 

Any ideas for how I could do that?

Thanks

Link to comment
https://forums.phpfreaks.com/topic/134400-view-index-in-descending-order/
Share on other sites

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.