This is my first post here, hopefully you guys can help me out. I don't quite know how to explain the problem I'm having with my PHP code but I'll try to explain it the best I can. Sorry in advance for the huge picture/long snippet of code.
So here is my problem:

I need to take the decimal places off/narrow it down to two decimals places. i.e. 183.47
Here is my PHP code for the page:
Code: Select all
<?php session_start();
ob_start();
include("db-connect/config.php");
include("includes/currency_config.php");
/* if(!isset($_SESSION['login_userid']))
{
header("location:index.php");
}*/
$sess_userid=$_SESSION['login_userid'];
$productid=$_REQUEST['pdid'];
$ip=$_SERVER['REMOTE_ADDR'];
$productsql=mysql_fetch_array(mysql_query("select * from product where id='$productid'"));
if(isset($_REQUEST['update']))
{
$objectid=$_POST['objectid'];
$blankid=$_POST['blankid'];
$smallsize=$_POST['smallsize'];
$mediumsize=$_POST['mediumsize'];
$largesize=$_POST['largesize'];
$xlargesize=$_POST['xlargesize'];
$xxlargesize=$_POST['xxlargesize'];
mysql_query("update addcart set smallquantity='$smallsize',mediumquantity='$mediumsize',largequantity='$largesize',xlargequantity='$xlargesize',
xxlargequantity='$xxlargesize' where userid='$ip' and productid='$objectid' and blankid='$blankid'");
header("location:shopping_cartmain.php");
}
if(isset($_REQUEST['remove']))
{
$objectid=$_POST['objectid'];
$blankid=$_POST['blankid'];
$cid=$_POST['oid'];
//mysql_query("delete from addcart where userid='$ip' and productid='$objectid' and blankid='$blankid'");
mysql_query("delete from addcart where cid='$cid'");
header("location:shopping_cartmain.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<title><?php echo $title;?></title> <meta name="keywords" content="<?php echo $webkeyword;?>" />
<meta name="description" content="<?php echo $webdes;?>" />
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function show1(divid)
{
if(document.getElementById(divid).style.display == "block")
{
document.getElementById(divid).style.display = "none";
}
else
{
document.getElementById(divid).style.display = "block";
}
}
</script>
<script language="javascript">
function updatevalidate(frm)
{
if(document.forms[frm].smallsize.value=="" && document.forms[frm].mediumsize.value=="" && document.forms[frm].largesize.value=="" && document.forms[frm].xlargesize.value=="" && document.forms[frm].xxlargesize.value=="")
{
alert("Enter the Quantity");
return false;
}
/*if(isNaN(document.forms[frm].smallsize.value) || isNaN(document.forms[frm].mediumsize.value) ||
isNaN(document.forms[frm].largesize.value) || isNaN(document.forms[frm].xlargesize.value) || isNaN(document.forms[frm].xxlargesize.value) )
{
alert("Quantity Should be Number Only");
return false;
}*/
var smallsize=parseInt(document.forms[frm].smallsize.value);
var mediumsize=parseInt(document.forms[frm].mediumsize.value);
var largesize=parseInt(document.forms[frm].largesize.value);
var xlargesize=parseInt(document.forms[frm].xlargesize.value);
var xxlargesize=parseInt(document.forms[frm].xxlargesize.value);
if(smallsize==0 || mediumsize==0 || largesize==0 || xlargesize==0 || xxlargesize==0)
{
alert("Quantity Should not be Zero");
return false;
}
if(smallsize < 0 || mediumsize < 0 || largesize < 0 || xlargesize < 0 || xxlargesize < 0)
{
alert("Quantity Should Not be Negative Value Only");
return false;
}
}
</script>
<script>
function relocate()
{
window.location.href='onlinestore.php';
}
</script>
<script type="text/javascript" src="lightbox.js"></script>
<link href="lightbox.css" rel="stylesheet" type="text/css" />
<link href="lightbox1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#fff"><?php include("header_menu.php"); ?></td>
</tr>
<tr>
<td valign="top" bgcolor="#fff"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="850"><table width="850" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td style="padding-bottom:20px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" id="body_left2"> </td>
<td valign="top" id="body_center2"> </td>
</tr>
<tr>
<td width="18%" height="600" valign="top" id="body_left"><table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" valign="top" class="user">BROWSE CATEGORY</td>
</tr>
<?php
$catsql11=mysql_query("select * from category where parent_id=''");
while($rowcat11=mysql_fetch_array($catsql11))
{
?>
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="brow_table">
<tr class="brow_table">
<td width="22%" align="left"> <img src="images/redstar.jpg" width="8" height="9" border="0" /></td>
<td width="78%" align="left">
<a href="products.php?pid=<?php echo $rowcat11['c_id']; ?>" ><?php echo $rowcat11['category']; ?></a></td>
</tr>
</table> </td>
</tr>
<tr>
<td>
<div id="subcat<?php echo $rowcat11['c_id']; ?>" style="display:none;">
<?php
$catsql12=mysql_query("select * from category where parent_id='$rowcat11[c_id]'");
while($rowcat12=mysql_fetch_array($catsql12))
{
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="brow_table">
<tr class="brow_table">
<td width="22%" align="left"> <img src="images/redstar.jpg" width="8" height="9" border="0" /></td>
<td width="78%" align="left"><?php echo $rowcat12['category']; ?></td>
</tr>
</table>
<?php } ?>
</div> </td>
</tr>
<?php } ?>
</table></td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td><img src="images/secured.jpg" width="161" height="123" border="0" /></td>
</tr>
<tr>
<td height="10"></td>
</tr>
</table></td>
<td width="61%" valign="top" id="body_LRight"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="center_head">Your Shopping Cart</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td valign="top" style="padding-top:3px;"> </td>
</tr>
<tr>
<td height="25">
<?php
$i=0;
$sum=0;
$select="select * from addcart where userid='$ip' and status='1'";
$cartquery=mysql_query($select);
$countcart=mysql_num_rows($cartquery);
if($countcart > 0)
{
$sum=0;
$whole_amount=0;
while($cartsql=mysql_fetch_array($cartquery))
{
$blankid=$cartsql['blankid'];
$objid=$cartsql['productid'];
$productsql=mysql_fetch_array(mysql_query("select * from product where id='$blankid'"));
$objectsql=mysql_fetch_array(mysql_query("select * from design where designid='$objid'"));
?>
<form name="cart<?php echo $i;?>" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="66%" class="bor_bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" class="design"> </td>
<td class="design"> </td>
<td class="text1"> </td>
</tr>
<tr>
<td width="21%" height="25" class="design">Style Name</td>
<td width="2%" class="design">:</td>
<td width="77%" class="text1"> <?php echo $productsql['p_name']; ?></td>
</tr>
<tr>
<td height="25" class="design">Design Name</td>
<td class="design">:</td>
<td class="text1"> <?php echo $objectsql['designname']; ?></td>
</tr>
<tr>
<td height="30" class="user"> </td>
<td class="design "> </td>
<td align="center"><img src="images/size.jpg" width="340" height="16" /></td>
</tr>
<tr>
<td height="30" class="user"> </td>
<td class="design"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5%" class="text2">S</td>
<td width="21%" height="35"><label>
<input name="smallsize" type="text" size="2" value="<?php echo $cartsql['smallquantity']; ?>"/>
</label></td>
<td width="4%" class="text2">M</td>
<td width="15%">
<input name="mediumsize" type="text" size="2" value="<?php echo $cartsql['mediumquantity']; ?>" /></td>
<td width="4%" class="text2">L</td>
<td width="16%">
<input name="largesize" type="text" size="2" value="<?php echo $cartsql['largequantity']; ?>"/></td>
<td width="5%" class="text2"> XL </td>
<td width="20%">
<input name="xlargesize" type="text" size="2" value="<?php echo $cartsql['xlargequantity']; ?>"/></td>
<td width="6%" class="text2">XXL</td>
<td width="4%">
<input name="xxlargesize" type="text" size="2" value="<?php echo $cartsql['xxlargequantity']; ?>"/></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%" height="50">
<input type="hidden" name="objectid" value="<?php echo $cartsql['productid']; ?>" />
<input type="hidden" name="oid" value="<?php echo $cartsql['cid']; ?>" />
<input type="hidden" name="blankid" value="<?php echo $cartsql['blankid']; ?>" />
<input name="update" type="submit" class="searchbg" value="Update" onclick="return updatevalidate('cart<?php echo $i;?>');"/>
</td>
<td width="4%"> </td>
<td width="76%"><input name="remove" type="submit" class="searchbg" value="Remove" /></td>
</tr>
</table></td>
</tr>
<?php
$amt=$productsql['range1'];
$qnty=($cartsql['smallquantity']+$cartsql['mediumquantity']+$cartsql['largequantity']+$cartsql['xlargequantity']+$cartsql['xxlargequantity']);
?>
<tr>
<td height="25" class="design">Total Quantity</td>
<td class="design">:</td>
<td class="text1"><?php echo $qnty; ?></td>
</tr>
<tr>
<td height="25" class="design">Unit Price</td>
<td class="design">:</td>
<td class="text1"><?php echo $productsql['range1'] ." ".$price_con_name; ?>
</td>
</tr>
<tr>
<td height="25" class="design"> </td>
<td class="design"> </td>
<td class="text1"> </td>
</tr>
</table></td>
<td width="34%" valign="top" class="bor_bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><a href="<?php echo $cartsql['waterimagepath']; ?>" rel="lightbox"><img src="<?php
echo $cartsql['waterimagepath']; ?>" width="148" height="135" border="0" class="img_border"/></a> </td>
</tr>
<?php
$amt=$productsql['range1'];
$qnty=($cartsql['smallquantity']+$cartsql['mediumquantity']+$cartsql['largequantity']+$cartsql['xlargequantity']+$cartsql['xxlargequantity']);
?>
<tr>
<td align="center">
<a href="<?php echo $cartsql['waterimagepath1']; ?>" rel="lightbox"><img src="<?php
echo $cartsql['waterimagepath1']; ?>" width="148" height="135" border="0" class="img_border"/></a></td>
</tr>
<?php
$amt=$productsql['range1'];
$qnty=($cartsql['smallquantity']+$cartsql['mediumquantity']+$cartsql['largequantity']+$cartsql['xlargequantity']+$cartsql['xxlargequantity']);
?>
<tr>
<td align="center"><span class="design">Total Price:</span> <span class="text1">$<?php echo $symbol." ". $productsql['range1']*$qnty; ?> </span></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php
/* $amt=$productsql['range1'];
$qnty=($cartsql['smallquantity']+$cartsql['mediumquantity']+$cartsql['largequantity']+$cartsql['xlargequantity']+$cartsql['xxlargequantity']);*/
$qn_ty=$qnty+$qn_ty;
$sum=$amt*$qnty;
$whole_amount = $whole_amount + $sum;
$i++;
}
}else
{ ?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td colspan="3" align="center"><font color="#FF0000"><strong>No Items</strong></font></td>
</tr>
</table>
<?php } ?>
</td>
</tr>
<tr>
<td class="hori_dot"> </td>
</tr>
<?php
if($countcart > 0)
{
?>
<tr>
<td height="25">
<form name="buynow" method="post" action="checklogin.php">
<table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#f5fafc">
<tr>
<td><!--<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="14%" height="30" class="design">Total Amount</td>
<td width="1%" class="design">:</td>
<td width="18%" class="text1"> Rs 200 </td>
<td width="18%" class="design"> Shipping charges</td>
<td width="1%" class="design">:</td>
<td width="19%" class="text1">Rs 25 </td>
<td width="13%" class="design"> Local Taxes</td>
<td width="1%" class="design">:</td>
<td width="15%" class="text1"> Rs 6 </td>
</tr>
</table> --></td>
</tr>
<tr>
<td class="newarrival"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="23%" height="30"><span class="design">Total Amount</span></td>
<td width="1%"><span class="design">:</span></td>
<td width="76%"><span class="text1"> <?php
//echo $qn_ty;
echo $price_symbol." ".$whole_amount ;?>
<input type="hidden" name="amount" value="<?php echo $whole_amount; ?>" />
<input type="hidden" name="quan_chk" value="<?php echo $qn_ty; ?>" /> </span></td>
</tr>
<tr>
<td height="30"><span class="design"> Shipping charges</span></td>
<td><span class="design">:</span></td>
<td><span class="text1"><?php
$cartquery11=mysql_query("select * from addcart where userid='$ip' and status='1'");
?>
<?php
$ship_sum=0;
while($cart_fetch=mysql_fetch_array($cartquery11))
{
$ship_qnty=($cart_fetch['smallquantity']+$cart_fetch['mediumquantity']+$cart_fetch['largequantity']+$cart_fetch['xlargequantity']+$cart_fetch['xxlargequantity']);
$ship_sum=$ship_qnty+$ship_sum;
}
if($ship_sum=='1')
{
$shipcharge=5;
}
else if($ship_sum=='2')
{
$shipcharge=5;
}
else if($ship_sum=='3')
{
$shipcharge=5;
}
else if($ship_sum=='4')
{
$shipcharge=5;
}
else
{
$shipcharge=$ship_sum*10;
}
//Shipping Amount
$shipcharge=$shipcharge*$c_shipcharge;
echo $price_symbol." ".$shipcharge;
?>
<input type="hidden" value="<?php echo $shipcharge; ?>" name="shipcharge" />
</span></td>
</tr>
<tr>
<td height="30"><span class="design"> Local Taxes</span></td>
<td><span class="design">:</span></td>
<td><span class="text1"> <?php
$vat_sql=mysql_fetch_array(mysql_query("select * from vat"));
$vat_per=$vat_sql['vat'];
//Local Taxes
echo $price_symbol." " . $vat=(($whole_amount*$vat_per*$c_shipcharge)/100);
?>
<input type="hidden" name="vat" value="<?php echo $vat; ?>" /> </span></td>
</tr>
</table></td>
</tr>
<tr>
<td class="newarrival"><span class="centerhead">Total Amount Payable :</span>
<!-- Total Amount -->
<?php echo $price_symbol." ".$total_amount=$whole_amount+$shipcharge+$vat;
$_SESSION['total_amount']=$total_amount;
?>
<input type="hidden" name="totalamount" value="<?php echo $total_amount; ?>" /> </td>
</tr>
<tr>
<td height="50"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="24%"> </td>
<td width="11%"><input name="Submit3" type="submit" class="searchbg" value="Buy Now" /></td>
<td width="65%"><input name="Submit4" type="button" class="searchbg" value="Continue Shopping" onclick="javascript: relocate(); "/></td>
</tr>
</table> <label></label></td>
</tr>
</table>
</form>
</td>
</tr>
<?php } ?>
<tr>
<td > </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top" ><?php //include("footer.php"); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>