kerbdog Posted February 19, 2011 Share Posted February 19, 2011 Hi all, Can you please advise if this code is right to display currency in a table cell in PHP and advise where I am going wrong????? <td>'number_format(.$_SESSION['itemprice'][$key], 2,".", ",".)'</td> Link to comment https://forums.phpfreaks.com/topic/228234-code-help-please/ Share on other sites More sharing options...
requinix Posted February 20, 2011 Share Posted February 20, 2011 Are you inserting this in the middle of some HTML? $ Link to comment https://forums.phpfreaks.com/topic/228234-code-help-please/#findComment-1176974 Share on other sites More sharing options...
andyd34 Posted February 20, 2011 Share Posted February 20, 2011 http://www.php.net/manual/en/function.number-format.php taken from the code hint $number = 1234.56; // english notation without thousands seperator $english_format_number = number_format($number, 2, '.', ''); // 1234.57 Link to comment https://forums.phpfreaks.com/topic/228234-code-help-please/#findComment-1176978 Share on other sites More sharing options...
kerbdog Posted February 20, 2011 Author Share Posted February 20, 2011 Hi Requnix No I am posting code in php. Full code below.... <?php //Script to delete product from cart. if(isset($_POST['submit'])) { $itemname = $_POST['h1']; //echo $_SESSION['itemname'][$itemname]; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='8' cellpadding='10' id='shopping_cart'>"; echo '<tr><form id="t1" method="post" action="summary.php" name="t1"><input type="submit" name="order" value="SUBMIT ORDER"></tr>'; echo "<tr><th bgcolor=#efefef>Date of Order</th bgcolor=#efefef> <th bgcolor=#efefef>Name</th> <th bgcolor=#efefef>Quantity</th> <th bgcolor=#efefef>Price</th> <th colspan='2'bgcolor=#efefef>Subtotal</th></tr>"; $date = date('h:i a , Dd M Y'); foreach($_SESSION['itemname'] as $key => $value) { //Loop sum of Subtotals to produce Grand Total $total += $_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key]; //Table showing Item Id reference, price per item and subtotal echo '<tr> <td>'.$date.'</td> <td>'.$_SESSION['itemname'][$key].'</td> <td><input type="text" name="t1" value='.$_SESSION['itemqty'][$key].'></td> <td>$'.$_SESSION['itemprice'][$key].'</td> <td header="subtotal">$'.($_SESSION['itemqty'][$key] * $_SESSION['itemprice'][$key]).'</td> <td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="h1" value='.$key.'></td> </tr> '; } //Echoing Grand total. echo ' <tr> <td colspan="4" bgcolor=#efefef><b>GRAND TOTAL</b></td><td colspan="2" bgcolor=#efefef><b>$'.$total.'</b></td> </table> '; ?> Link to comment https://forums.phpfreaks.com/topic/228234-code-help-please/#findComment-1176981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.