[FX.php List] Creating summaries on the fly,

Dale Bengston dbengston at preservationstudio.com
Tue Aug 22 21:55:05 MDT 2006


Hey Bob,

This is just hacked up in the email, so I don't guarantee every line.  
As you're ticking through your records, increment some array elements  
based on your summary field content....

$summaryCount = array();
$recCount = 0;

foreach ($theRecords as $key => $value)
	{
	$summaryCount[$value['myField'][0]]++;

	[...other stuff]
	$recCount++;
	}


This creates an array element for each subcategory and increments it  
on the fly. When the foreach is done processing, you have a count of  
each subcategory, plus a total count of records. The percentage of  
each subcategory is...

($summaryCount['whatever'] / $recCount) * 100;

Am I making sense at this hour?

Dale

On Aug 22, 2006, at 10:44 PM, Kevin Futter wrote:

> On 23/8/06 1:06 PM, "Bob Patin" <bob at patin.com> wrote:
>
>> Thanks for the reply.
>>
>> Unfortunately, that won't work, since I have no way of knowing how  
>> many subsummaries there will be, or how many totals there will be  
>> for each category.
>>
>> I originally thought about doing this in the database itself, but  
>> summarizing in PHP works great. The only catch is these  
>> percentages...
>>
>> At this point I'm not too concerned about the non-Javascript  
>> folks; if they want to use the reports and get all the data,  
>> they'll have to have Javascript. The question is, how to plug a  
>> piece of text into a page.
>>
>> I know how to populate a form field in JS, but how do I insert a  
>> piece of text somewhere in an HTML (actually of course PHP) page?
>>
> Well, probably the simplest method would be to create an empty  
> element on the page to contain the percentage info – I don’t know  
> your page structure so I’ll leave it to you to decide what the most  
> semantic choice of element is. You’ll need to give it an ID, so if  
> you require more than one, append an incrementing number to the ID  
> name (eg, id-name1, id-name2 etc).
>
> The JS would need to contain a line like so:
>
> document.getElementById(“id-name1”).innerHTML = “30%”;
>
> I can elaborate further with a complete script example if you need it.
>
> -- 
> Kevin Futter
> Webmaster, St. Bernard's College
> http://www.sbc.melb.catholic.edu.au/
>
> ------------------------------------------
> This e-mail and any attachments may be confidential. You must not  
> disclose or use the information in this e-mail if you are not the  
> intended recipient. If you have received this e-mail in error,  
> please notify us immediately and delete the e-mail and all copies.  
> The College does not guarantee that this e-mail is virus or error  
> free. The attached files are provided and may only be used on the  
> basis that the user assumes all responsibility for any loss, damage  
> or consequence resulting directly or indirectly from the use of the  
> attached files, whether caused by the negligence of the sender or  
> not. The content and opinions in this e-mail are not necessarily  
> those of the College.
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20060822/5380ea45/attachment.html


More information about the FX.php_List mailing list