Mohammad Mohammad - 3 months ago 20
MySQL Question

How to update the SQL table

I am looking to insert the

web_salescart
table:

$insert_row = $conn->query(
"INSERT INTO web_salescart (cartnumber, branchcode, stockid, qty, price, descr, salesman, date, time, brname,discount)
VALUES ('".$_SESSION['CART']."', '".$_SESSION['BRANCHCODE']."', '".$item_data['stockid']."', '".$item_data['qty']."', '".$item_data['unit_price']."', '".mysql_real_escape_string($item_data['description'])."', '".$_SESSION['salescode']."', '".date("m-d-y")."', '".date("g:i a")."', '".mysql_real_escape_string($_SESSION['BRNAME'])."','".$item_data['discount']."')");


Here
$item_data['discount']
is updating 33%. I need to update it as 0.33 in web_salescart table and 33% is the display figure. Can I use an update statement right after the INSERT so that $item_data['discount'] is divided by 100?

Answer

Convert it to 0.33 when you insert it, not as a separate query. In the query, replace $item_data['discount'] with:

number_format(str_replace('%', '', $item_data['discount'])/100, 2)
Comments