Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

HTML_Graphs
I wanted to be able to hand a simple database query to a function and have it graph it without me going to a bunch of work, so I whipped up this little function. It takes a database result and a title. The database result should be from a simple query like "select group, count(*) from table group by group". Just two columns, with the first column being the labels, and the second column being numbers.

<?php

include("class-graphs.php3");

Function
GraphResult($result,$title) {

/*
    Takes a database result set.
    The first column should be the name,
    and the second column should be the values
*/

    /*
        db_ should be replaced with your database, aka mysql_ or pg_
    */
    
$rows=db_NumRows($result);

    if ((!
$result) || ($rows < 1)) {
        echo
"None Found.\n";
    } else {
        
$names[];
        
$values[];

        for (
$j=0; $j < db_NumRows($result); $j++) {
            if (
db_result($result, $j, 0) != "" && db_result($result, $j, 1) != "" ) {
                
$names[$j]= db_result($result, $j, 0);
                
$values[$j]= db_result($result, $j, 1);
            }
        }

    
/*
        This is another function detailed below
    */
        
GraphIt($names,$values,$title);
    }
}

?>
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
rectangular coordinats system graphs. mitchell penneau06/08/05 12:18
php upload one imagetndvrs03/01/05 12:53
Tell me how to install GD into a Unix (Darwinjeanloui09/21/03 05:16
tell me about apache and unix in laban09/20/02 09:48
RE: JPGraph does this - but how...Markus06/05/02 06:29
RE: JPGraph does this - but how...Markus06/04/02 14:01
RE: Create a bar chart in PHP / HTML?fareed06/01/02 01:14
creating a GIFTom Fritsch12/10/01 18:43
RE: Create a bar chart in PHP / HTML?Thomasson10/21/01 12:35
graphsPer Kummervold08/06/01 05:58
RE: Create a bar chart in PHP / HTML?Deepak07/27/01 02:51
JPGraph does this - but how...Owen Lees07/08/01 14:07
Create a bar chart in PHP / HTML?Jacky Hung06/01/01 08:32
RE: Tell me ,can I use the GD library in PHP41pl2zealousness05/29/01 06:18
Html GraphsSean Dowell05/04/01 11:58
on the fly gif graphsGeorge Kesarios03/10/01 12:14
GifPix.class - without GD or tablesRoberto Bertó02/19/01 03:55
interesting and very usefulkatherine12/28/00 21:27
way cool sitenduati githae12/21/00 02:54
How can I use this with templates?Gary Smith11/21/00 20:48
I have done it before.Ahmad Anvari11/08/00 15:37
Enhancements to wrapper (2) Rob Watkins09/06/00 09:43
Enhancements to wrapper (1) Rob Watkins09/06/00 09:40
Tell me ,can I use the GD library in PHP41pl2Ting.Xu07/14/00 18:05
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.