How do I get the first result of this query using php? I want the first result that is returned when the list is in descending开发者_运维问答 order.
$sql2 = "SELECT orderID FROM orders WHERE 'customerID' = '".$_SESSION['accountID']."' ORDER BY
'orderID' DESC";
$lastorder = mysqli_query($sql2);
Thanks!
Simply add LIMIT 1
to the end of your SQL
Use LIMIT
:
'SELECT orderID FROM orders WHERE customerID = "' . $_SESSION['accountID'] . '" ORDER BY orderID DESC LIMIT 1'
The query:
$query = "SELECT MAX(orderID) as orderID
FROM orders
WHERE customerID = '" . $_SESSION['accountID'] . "'";
If customerID is a number then the single quotes can be removed to make the query:
$query = "SELECT MAX(orderID) as orderID
FROM orders
WHERE customerID = " . $_SESSION['accountID'];
Then...
// include database_link since you are not using OO-style call.
$result = mysqli_query($database_link, $query);
$row = $result->fetch_object();
$orderID = $row->orderID;
精彩评论