How to get the last value (not the id) of a table ?
Posted: Sun Feb 10, 2008 3:58 pm
I know mysql_insert_id() retrieves the last inserted ID, but I need to retrieve just the last value of a particular column. This table doesn't have any auto increment field. It only has one column - cart. I can't change the database stucture so cant add an auto increment field.
When I call the following function I don't get any value even though the value was just saved into the database.
Am I making any mistake when I say : $cart=mysql_result($result,0) ?
Is it not supposed to retrieve the last saved value?
When I call the following function I don't get any value even though the value was just saved into the database.
Am I making any mistake when I say : $cart=mysql_result($result,0) ?
Is it not supposed to retrieve the last saved value?
Code: Select all
function getCart() {
global $cart;
// if this is a new cart, then create a cart_no using the current time stamp.
// otherwise extract the cart_id from the session variable
if (!$cart)
{
$cart_id = date("d-m-Y-H-i-s");
$sql ="INSERT INTO cart VALUES('".$cart_id."')";
$result=mysql_query($new_cart_id_q);
$cart=mysql_result($result,0);
return $cart;
}
else
{
$cart= $_SESSION['cart'];
}
}