|
Mysql et un pie chart |
Posted by Seveso on Jul-25-2016 21:50 |
|
Hi everyone,
i'm not very good en english and i try to explain my problem the most complete i can.
I have a database: "annuaire"
I have tables inside witch one call : "contact"
In this table "contact", i have a column with "titre"
I take the pie chart to improuve my php and mysql.
I try to make a pie chart with the information of the column "titre" of the table "contact"
le value in the column "titre" are "Monsieur, Madame, Docteur ..."
I have an include for the database connexion call:
include ('acces_base');
I know that i must do:
- connexion database
- requete database
- fetch information
but i don't know where i put this information ?
I hope you understand my problem ?
And if you speak french ....?
Tx for answer. |
Re: Mysql et un pie chart |
Posted by Peter Kwan on Jul-26-2016 02:18 |
|
Hi Seveso,
To plot a pie chart, you need two sequences, one for the labels, and the other for the data values. For your case, you just need to create an SQL to get the two columns for the 2 sequences.
In your post, you mentioned there is only one column "titre", which are "labels". I am not sure where are the data values. Do you mean you want to count the frequency of the "titre"? If this is the case, please write an SQL that counts the frequency and output two columns for the labels and for the count. For example, you can use a GROUP BY query, like:
$SQL = "Select titre, Count(titre) From contact GROUP BY titre";
Then you can just connect to the database, issue the query, and read the results:
mysql_connect("address_of_database", "username", "password");
mysql_select_db("annuaire");
$result = mysql_query($SQL);
while ($row = mysql_fetch_row($result)) {
$labels[] = $row[0];
$data[] = $row[1];
}
Then you can use the $labels and $data to plot charts.
Regards
Peter Kwan |
|