Solved

Number format

Posted on 2007-12-05
8
227 Views
Last Modified: 2008-02-01
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
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20414363

<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
 
LVL 20

Expert Comment

by:steelseth12
ID: 20414374
$row1["sum_circulation"] is referencing a value in the array so you can treat it the same as a variable.
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 20414386
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 20414394
Since you are using concatenation, you can just replace each

. $row1["sum_circulation"] .

with  

. number_format($row1["sum_circulation"]) .
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20414405
Thats 2 things you learned today. 1 never get married and 2 how to access arrays :)
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 20414411
@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
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 20414418
>>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
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 20414604
You're welcome, my posting was just meant to help clarify what he said, anyway, so no points expected :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question