For example,1998 has 100 items,1999 has 120 items, 2000 has items...Then,i wan to calculate the total of the items for each year, then come out the graph by using the php code.......So,does anyone know how to do it???Thanks....
How to generata the data in graph???
Moderator: General Moderators
-
teckyan888
- Forum Commoner
- Posts: 40
- Joined: Tue May 11, 2004 10:46 am
How to generata the data in graph???
Anyone who know how to generate the data inside the database???
For example,1998 has 100 items,1999 has 120 items, 2000 has items...Then,i wan to calculate the total of the items for each year, then come out the graph by using the php code.......So,does anyone know how to do it???Thanks....
For example,1998 has 100 items,1999 has 120 items, 2000 has items...Then,i wan to calculate the total of the items for each year, then come out the graph by using the php code.......So,does anyone know how to do it???Thanks....
Without knowing the structure of the table in the database that holds the information, i can't give you the exact code.
However, assuming that a column called my_item_name and once called my_year exists in the table called my_data, and the data looks something like
my_item_name my_year
item1 1998
item2 1998
item3 1999
item4 2000
item5 1999
...
then the SQL you would need is
As for graphing, I don't know. are you using a 3rd party graphing library?
Hope this helps
However, assuming that a column called my_item_name and once called my_year exists in the table called my_data, and the data looks something like
my_item_name my_year
item1 1998
item2 1998
item3 1999
item4 2000
item5 1999
...
then the SQL you would need is
Code: Select all
SELECT
count(my_item_name) as total,
my_year
FROM
my_data
GROUP BY
my_year
ORDER BY
my_year ASC
;Hope this helps
If the data is inside the db - and you know the SUM() just pass it as a variable, if not - use SUM() for integer values in fields, or COUNT() if you need number of fields that match the criteria
For graphing:
Use this (untested):
You should get horizontal bar chart/graph.
This'll get you started - develop the idea to a greater level ( and give me the better version
)
For graphing:
Use this (untested):
Code: Select all
<?php
for ( $i = 0; $i < $db_result_returned; $i++ )
{
echo "<img src='some_url'>";
}
// $db_result_returned - the SUM() or COUNT() result from the db for one year
// this image inside the for loop - create small rectangular image - color is for you to choose and save it somewhere. Just enter the right path inside the src="...." part.
?>This'll get you started - develop the idea to a greater level ( and give me the better version
-
teckyan888
- Forum Commoner
- Posts: 40
- Joined: Tue May 11, 2004 10:46 am
- AVATAr
- Forum Regular
- Posts: 524
- Joined: Tue Jul 16, 2002 4:19 pm
- Location: Uruguay -- Montevideo
- Contact:
if you want to make dinamic graphs: http://www.aditus.nu/jpgraph/
-
teckyan888
- Forum Commoner
- Posts: 40
- Joined: Tue May 11, 2004 10:46 am
-
teckyan888
- Forum Commoner
- Posts: 40
- Joined: Tue May 11, 2004 10:46 am
Sorry...i am newbie for php...Is it install at here:
C:\Program Files\Apache Group\Apache2\htdocs
Then, if the error message got show:
So,where should i change the DIR and change to which directory???anywho who know it??thanks...
C:\Program Files\Apache Group\Apache2\htdocs
Then, if the error message got show:
Code: Select all
<?php
JpGraph Error: No path specified for CACHE_DIR. Please specify a path for that DEFINE in jpgraph.php
?>