• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Number format

I am trying to add in commas on my website and I came across this - http://us2.php.net/number_format - is that what I want.

EX: 45000 to make it 45,000

Here is the page I want it on - http://www.newspapersofamerica.com/new/index.php?p=daily

$english_format_number = number_format($number);

Since I am using arrays to print them out..that is the part I am confused about:

' . $row1["sum_circulation"] . '

instead of

$sum_circulation

Thanks,
Ryan

Below is my full code
<h2>States</h2>
        <table id="state">
<?php
error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors","On");
$query = mysql_query("SELECT COUNT(*) as paper_number, SUM(b.circulation) as sum_circulation , a.state_name,a.state_id FROM states a INNER JOIN papers b ON a.state_id=b.state_id GROUP BY a.state_id") or die(mysql_error());
$i=1;
 
$a = $b = $c = "";
 
while($row1 = mysql_fetch_array($query))
{
 
    if(($i%2)){
	
        $a = '<tr><td width="200" class="st"><a href="?p=papers&state='.$row1["state_id"].'">'.$row1["state_name"].'</a></td>' . "\n";
        $b = '<tr><td class="ct"><b>Number of Papers:</b> ' . $row1["paper_number"] . '</td>' . "\n";
        $c = '<tr><td class="ct"><b>Total Circulation:</b> ' . $row1["sum_circulation"] . '</td>' . "\n";
    }
    else{
	
        $a .= '<td width="200" class="st"><a href="?p=papers&state='.$row1["state_id"].'">'.$row1["state_name"].'</a></td></tr>' . "\n";
        $b .=  '<td class="ct"><b>Number of Papers:</b> ' . $row1["paper_number"] . '</td></tr>' . "\n";
        $c .=  '<td class="ct"><b>Total Circulation:</b> ' . $row1["sum_circulation"] . '</td></tr>' . "\n";
   
 		  print $a.$b.$c;
    }
 
	$i++;
	  
}
if(mysql_num_rows($query)%2) {
        $a .='<td>&nbsp;</td></tr>';
        $b .='<td>&nbsp;</td></tr>';
        $c .='<td>&nbsp;</td></tr>';
		
		print $a.$b.$c;
}	
?>
</table>

Open in new window

0
catonthecouchproductions
Asked:
catonthecouchproductions
  • 3
  • 3
  • 2
1 Solution
 
steelseth12Commented:

<h2>States</h2>
        <table id="state">
<?php
error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors","On");
$query = mysql_query("SELECT COUNT(*) as paper_number, SUM(b.circulation) as sum_circulation , a.state_name,a.state_id FROM states a INNER JOIN papers b ON a.state_id=b.state_id GROUP BY a.state_id") or die(mysql_error());
$i=1;
 
$a = $b = $c = "";
 
while($row1 = mysql_fetch_array($query))
{
 
    if(($i%2)){
        
        $a = '<tr><td width="200" class="st"><a href="?p=papers&state='.$row1["state_id"].'">'.$row1["state_name"].'</a></td>' . "\n";
        $b = '<tr><td class="ct"><b>Number of Papers:</b> ' . number_format($row1["paper_number"]) . '</td>' . "\n";
        $c = '<tr><td class="ct"><b>Total Circulation:</b> ' . number_format($row1["sum_circulation"]) . '</td>' . "\n";
    }
    else{
        
        $a .= '<td width="200" class="st"><a href="?p=papers&state='.$row1["state_id"].'">'.$row1["state_name"].'</a></td></tr>' . "\n";
        $b .=  '<td class="ct"><b>Number of Papers:</b> ' . number_format($row1["paper_number"]) . '</td></tr>' . "\n";
        $c .=  '<td class="ct"><b>Total Circulation:</b> ' . number_format($row1["sum_circulation"]) . '</td></tr>' . "\n";
   
                  print $a.$b.$c;
    }
 
        $i++;
          
}
if(mysql_num_rows($query)%2) {
        $a .='<td>&nbsp;</td></tr>';
        $b .='<td>&nbsp;</td></tr>';
        $c .='<td>&nbsp;</td></tr>';
                
                print $a.$b.$c;
}       
?>
</table>

Open in new window

0
 
steelseth12Commented:
$row1["sum_circulation"] is referencing a value in the array so you can treat it the same as a variable.
0
 
catonthecouchproductionsAuthor Commented:
That worked! Thank you. I didnt know that it would be that easy just to place the row array within that function.

>>$row1["sum_circulation"] is referencing a value in the array so you can treat it the same as a variable.
    I never knew that.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Cornelia YoderArtistCommented:
Since you are using concatenation, you can just replace each

. $row1["sum_circulation"] .

with  

. number_format($row1["sum_circulation"]) .
0
 
steelseth12Commented:
Thats 2 things you learned today. 1 never get married and 2 how to access arrays :)
0
 
catonthecouchproductionsAuthor Commented:
@yodercm: Sorry! Steel got me a solution..two minutes late. I know I will have another one soon..I am sure.. stay tuned.

I appreciate your help anyway.. thank you very much.
0
 
catonthecouchproductionsAuthor Commented:
>>Thats 2 things you learned today. 1 never get married and 2 how to access arrays :)

        Great GREAT GREATT lessons of the day..ill keep those handy, haha!
0
 
Cornelia YoderArtistCommented:
You're welcome, my posting was just meant to help clarify what he said, anyway, so no points expected :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now