/    Sign up×
Community /Pin to ProfileBookmark

hi, how do i make a graph in php, but, the code has to connect to a server to get the values for the graph.
If any of you can help me with the code, i have found many examples but no one that conects to a server (database) and get the values from there and then graphic them.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@darkcminorauthorJul 16.2006 — like this but i need that it connects to a server and get the values, please help

<?php

$dnum[1]=25;

$dnum[2]=20;

$dnum[4]=15;

$dnum[7]=23;

$allmonth=7;

function graph($allmonth, $dnum) {

$maxdnum=ceil(max($dnum)); //find out the maximal value of array

if ($maxdnum>=50) { $xnum=1; } //set scale of graph to 100%

elseif ($maxdnum>=20) { $xnum=2; } //set scale of graph to 50%

elseif ($maxdnum>=10) { $xnum=5; } //set scale of graph to 20%

elseif ($maxdnum>=5) { $xnum=10; } //set scale of graph to 10%

elseif ($maxdnum>=0) { $xnum=20; } //set scale of graph to 5%

echo "<br><table align=center width=100% border=1>";
echo "<tr bgcolor=cyan align=center><td>Month</td>";
for ($i=1; $i<=100; $i++) { echo "<td></td>"; }
echo "<td>%</td></tr>";
for ($k=1; $k<=$allmonth; $k++) {
if ( !isset($dnum[$k]) ) {
$dnum[$k]='NA'; //set value to missed month
}
echo "<tr align=center><td>$k</td>";
if ($dnum[$k] !='NA') {
$dgraph[$k]=round($dnum[$k]*$xnum);
$rgraph=100-$dgraph[$k];
}else {
$dgraph[$k]=0; $rgraph=100;
}
for ($i=1; $i<=$dgraph[$k]; $i++) { echo "<td bgcolor=red></td>"; }
for ($j=1; $j<=$rgraph; $j++) { echo "<td bgcolor=#dedede></td>"; }
echo "<td>$dnum[$k]</td></tr>";
}
echo "</table>";

}

?>
Copy linkTweet thisAlerts:
@NogDogJul 17.2006 — What kind of database (MySQL, Oracle, etc.)?
Copy linkTweet thisAlerts:
@Haafiz_DossaJul 17.2006 — You can develop your own graph generation script using the GDLib functions...or a simpler alternative would be to use the PEAR's Image_Graph:

http://pear.php.net/package/Image_Graph

It can do some pretty cool stuff:

http://pear.veggerby.dk/samples/



i have found many examples but no one that conects to a server (database)
[/QUOTE]

If that's the case, and you want to use those scripts, then you can just connect to the database, fetch the results and store them in an Array, and then use the other examples you found to just use the Array (I assume they take Array inputs).

Could you be specific as to what kind of graph you need (bar, pie, line, etc...)?
Copy linkTweet thisAlerts:
@darkcminorauthorJul 17.2006 — well, hi again, i need a bar graphic, but i would very glad if you could send me the code for conecting and getting the array for an object already defined in the server,

i mean a person introduce some values, i get them then the data stores in a table

(in a server)

and i need to get those values and graph them, and when other person give other values (that store on the server), and then the code has to do the same thing get them and graph them, i dont know if you please send me a code to do this because

i am very lost

thank you for bothering you.
Copy linkTweet thisAlerts:
@darkcminorauthorJul 17.2006 — sorry, the server is in mysql,

well, any help is very useful thanks
×

Success!

Help @darkcminor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...