Jump to content

Change output of a PHP CLI file add commas?


chadrt

Recommended Posts

Ok so I have this script that I wrote and it works really good.  I wanted to display the number of records in a table and since the db only changes once per day I thought I would put the couner on the back end.  I have this script that changes the value of the text file every day.  But I would love it if it outputted with commas.

 

Now it reads:

1234070

 

Want it to read:

1,234,070

 

Any thoughs?

#!/usr/bin/php -q
<?php
$username=""; // READONLY USER USED HERE AND AUTH'D ON LOCALHOST ONLY
$password="";
$database="";
$dbhost="";

mysql_connect($dbhost,$username,$password);
@mysql_select_db($database) or die( "Unable to connect to database please try again!");

$counthd=mysql_query("SELECT count(*) as total from HD");
$hdtotal=mysql_fetch_assoc($counthd);
$dbcount = $hdtotal['total'];
echo "";

$myFile = "dbcounter.txt";
$fh = fopen($myFile, 'w');
fwrite($fh, "$dbcount");
fclose($fh);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.