<html> <head> <title>Rough Diamond
Information</title> </head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("basic");
$order = "select * from calculator ";
$result=mysql_query($order);
echo "Rough Diamonds Information: ";
echo "<a href='home.html'>Go to main page <br><br>";
?>
<table border="1" style="width:50%">
<tr>
<th><b>ID</b></th>
<th><b> Name</b></th>
<th><b> Total Rough Weight</b></th>
<th><b>One Carat Price</b></th>
<th><b>Dollar Rate</b></th>
<th><b>Payment Days</b></th>
<th><b>Total Payment</b></th>
</tr>
<?php while($row = mysql_fetch_array($result) ) {
echo "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['total_wt']."</td>
<td>".$row['crt_price']."</td>
<td>".$row['dollar_rate']."</td>
<td>".$row['pay_day']."</td>
<td>".$row['total_price']."</td>
</tr>";} ?>
</body>
</html>
Asked
Active
Viewed 480 times
1
-
1someone pls edit dis code in viewable format – John Oct 23 '15 at 06:07
-
Please specify error and desired output – Disha V. Oct 23 '15 at 06:07
-
this code is for fetcching value from database. i want all value in this format. eg (3,00,000) – John Oct 23 '15 at 06:08
4 Answers
2
Use number_format($number);
.

Ashwini Agarwal
- 4,828
- 2
- 42
- 59
-
`
".$row['total_price']." ` --> `".number_format($row['total_price'])." ` – Ashwini Agarwal Oct 23 '15 at 06:16
1
Use money_format
to format Currency like this.
$amount = '300000';
setlocale(LC_MONETARY, 'en_IN');
$amount = money_format('%!i', $amount);
echo $amount; // 3,00,000.00
Here is the helping link Link

Community
- 1
- 1

Ashish Choudhary
- 2,004
- 1
- 18
- 26
0
create a function and display the number as follows
function moneyFormatIndia($num){
$explrestunits = "" ;
if(strlen($num)>3){
$lastthree = substr($num, strlen($num)-3, strlen($num));
$restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits
$restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
$expunit = str_split($restunits, 2);
for($i=0; $i<sizeof($expunit); $i++){
// creates each of the 2's group and adds a comma to the end
if($i==0)
{
$explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer
}else{
$explrestunits .= $expunit[$i].",";
}
}
$thecash = $explrestunits.$lastthree;
} else {
$thecash = $num;
}
return $thecash; // writes the final format where $currency is the currency symbol.
}
<?php while($row = mysql_fetch_array($result) ) {
echo "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['total_wt']."</td>
<td>".$row['crt_price']."</td>
<td>".$row['dollar_rate']."</td>
<td>".$row['pay_day']."</td>
<td>".moneyFormatIndia($row['total_price'])."</td>
</tr>";} ?>

Gunasegar
- 161
- 1
- 9