Search code examples
phpmysqlnumbers

Apply comma to numbers in td of table


I have a list of numbers in a table resulting from mySQL:

How do I apply the comma to the number fields: "min" and "max"

$query = "SELECT min, max, qty FROM cartons_current LIMIT 0,50";
$result = $db->query($query, MYSQLI_STORE_RESULT);
$o = '<table><thead><tr><th>Min</th><th>Max</th><th>Qty</th></tr></thead><tbody>';
while(list($min, $max, $qty) = $result->fetch_row()) {

$o .= '<tr><td>'.$min.'</td><td>'.$max.'</td><td>'.$qty.'</td></tr>';}
$o .= '</tbody></table>';
echo $o;
?>

Solution

  • You probably want to use number_format().

    https://www.php.net/manual/en/function.number-format.php