Jump to content

Change output of a PHP CLI file add commas?


chadrt
Go to solution Solved by QuickOldCar,

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);

?>
Edited by chadrt
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.