0

My code I'm working on has a table db the data is 4.5 I wanted it to be 4.50 any help would be great.

here's my code:

<?php 
	
	  
  $con = mysql_connect("localhost", "root", "");
  
  if(!$con)  //If we can't connect then stop trying and say so
{
	die("Could not connect to server: ". mysql_error());
}
mysql_select_db("inventory_db", $con);
$query = "SELECT * FROM item_inventory";
echo "<table border='1' cellpadding='10' align='center' cellspacing='7'>
<tr>
<th>Item Name</th>
<th>Description</th>
<th>Price</th>
</tr>";
$result = mysql_query($query)
or die("Error " . mysql_error());

while($row = mysql_fetch_array($result))
  {
  	echo "<tr>";
  	echo "<td>" .  $row[ 'ItemName' ] . "</td>";
	echo "<td>" . $row['Description'] . "</td>";
	echo "<td>$" . $row['Price' ] . "</td>"; 	
 	echo "</tr>";
  }
echo "</table>";

mysql_close($con);

keep in mind that the price table date needs to have this pricison "#.##"

Edited by SCoder1: No code!

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by almostbob
0

actually the table data does not require this precision, only the output data does
given the table column is returned as $row['price'] at line 26 in the original

$format_number = number_format($row['price'], 2, '.', ''); /* orignal number, 2 dec, dot sepaarated, nothing between thousands */
echo "<td>$".$format_number."</td>";

or

echo "<td>$".number_format($row['price'], 2, '.', '')."</td>";

php.net reference

Edited by almostbob: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.