I have a little problem. I use the html table shape as the output in the php query. I want to use the x.xxx,xx shape for the inventory total field. however, numberformat did not work.
how do I do it .?
number_format({$item['stok_toplam']}) is not work .
<?php
try
{
$db = new PDO("sqlsrv:Server=192.168.15.153,1433;Database=MikroDB_V16_2021", 'user', 'password');
$data = $db -> query("SELECT msg_S_0014, msg_S_0785, sum(msg_S_0165) as stok_toplam FROM STOKLAR_YONETIM_Mobile where msg_S_0001 LIKE 's%' group by msg_S_0014,msg_S_0785 order by msg_S_0014")->fetchAll();
//Kayıt sayısı ekrana bastırılacak.
echo count($data)."</br>"."</br>";
foreach ($data as $item)
echo "<table border=1 cellspacing=0 cellpading=0 >
<tr> <td style='color:green' width=150px>$item[msg_S_0014]</td><td style width=150px>$item[msg_S_0785]<td style width=150px align=right>$item[stok_toplam]</font></td></tr>
</table>";
}
catch (Exception $exception)
{
//Eğer bağlantı sırasında bir hata oluşursa ekrana oluşan hata bastırılacaktır.
echo $exception->getMessage();
}
?>
CodePudding user response:
First of all you need to use single quotes to define the array offset. Define the variables, then echo them to html. Or use template tags. Like this:
foreach ($data as $item) {
echo "<table border=1 cellspacing=0 cellpading=0 >
<tr> <td style='color:green' width=150px>{$item['msg_S_0014']}</td><td style width=150px>{$item['msg_S_0785']}<td style width=150px align=right>{$item['stok_toplam']}</font></td></tr>
</table>";
}
CodePudding user response:
I edited it as follows. it's working fine.
foreach ($data as $item) {
$para = number_format($item['stok_toplam'], 0, ',', '.');
echo "<table border=1 cellspacing=0 cellpading=0 >
<tr> <td style='color:green' width=150px>{$item['msg_S_0014']}</td><td style width=150px>{$item['msg_S_0785']}<td style width=150px align=right>{$para}</font></td></tr>
</table>";
}