Hi,
I'm having a problem getting a select statement to work the way I want it to. I have an HTML table displaying finance information that I want to plug in some values from a mySQL database.
I make one query that returns the name of a particular organization. I then use this name that is returned inside of another query to return the most recent financial information for this organization.
Here's my code:
$owed_to = mysql_result($stuff,$i,"owed_to");
$owedStuff = mysql_query(
"SELECT amt_owed
FROM Finance
WHERE (owed_to = '$owed_to')
ORDER BY unix_date
DESCEND");
$amt_owed = mysql_result($owedStuff,0,"amt_owed");
$interest_rate = mysql_result($stuff,$i,"interest_rate");
$description = mysql_result($stuff,$i,"description");
echo("<tr><td>$owed_to</td><td>$" . "$amt_owed</td><td>$interest_rate" . " %</td><td>$description</td></tr>");
The code works fine if I don't use the DESCEND option in the SQL query. But that gives me the wrong results. It gives me the oldest information because "unix_date" is a UNIX timestamp.
So, can anyone tell me why the DESCEND option may not be working, or suggest a possible fix. What I want is the most recent information according to the UNIX timestamp contained in "unix_date".
I suppose I could figure out how many rows are returned after running the "owedStuff" query, and then get the information in the last row, but I don't know how to do this.
I hope all of this is clear.
Thanks for any help,
George