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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.