473,392 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,392 software developers and data experts.

generate bar / graph from database

I got an online survey working where each submission outputs to a table
on another page. It works, but now I would like to be able to create
another page that would show the totals in a bar / graph. There are 5
questions with 6 radio buttons each (and a comments field). There is
also one drop-down menu I would like to interpret as well. Can anyone
point me to a good tutorial. Most of the scripts I've seen starts with
creating a poll which I've already done.
Jul 17 '05 #1
3 3288
I noticed that Message-ID: <LP**********************@news.easynews.com>
from Neal contained the following:
It works, but now I would like to be able to create
another page that would show the totals in a bar / graph. There are 5
questions with 6 radio buttons each (and a comments field). There is
also one drop-down menu I would like to interpret as well.


A bit like this perhaps?
http://www.ckdog.co.uk/php/voting/re...php?ballotid=3

I assume you have a method of storing your results?

All I did here was to set the percentage width of a single pixel .gif to
the required width. But you could just as easily do it with divs or
table cell widths.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
Geoff Berrow wrote:
A bit like this perhaps?
http://www.ckdog.co.uk/php/voting/re...php?ballotid=3

I assume you have a method of storing your results?

All I did here was to set the percentage width of a single pixel .gif to
the required width. But you could just as easily do it with divs or
table cell widths.


yes.....something like that. My results are stored in MySQL database
with fields qone, qtwo, qthree, etc...
Each question has 6 possible answers / values ranging from Excellent to
Unsatisfactory. Can I see your source code?
Jul 17 '05 #3
I noticed that Message-ID: <Km**********************@news.easynews.com>
from Neal contained the following:
yes.....something like that. My results are stored in MySQL database
with fields qone, qtwo, qthree, etc...
Each question has 6 possible answers / values ranging from Excellent to
Unsatisfactory. Can I see your source code?


Because this is designed to be re-used for all sorts of different votes,
I store the choices as a comma separated list in the ballot table, but
of course there is only one question. Anyway, if it helps, see below
for the relevant bit of code. Looking through it, I think the html is a
little screwed, but it works and the only thing the validator picks up
is missing alt attributes on the .gifs used for the bars..

....
$ballotid=$_GET['ballotid'];
$db = @mysql_connect("server", "user", "password")or
die("Could not connect: " . mysql_error());;
mysql_select_db("database_name",$db);

$sql="SELECT * from ballot WHERE ballotid='$ballotid' AND
end_date>now()";
$result = mysql_query($sql);
$vote_finished = mysql_num_rows($result);

$sql="SELECT * from ballot,vote,voter WHERE ballot.ballotid='$ballotid'
AND ballot.ballotid=vote.ballotid and voter.voterid=vote.voterid AND
vote.confirmed='Yes'AND (status is null OR status='OK')";
$result = mysql_query($sql);
$totalrows = mysql_num_rows($result);
$myrow = mysql_fetch_array($result);
?>
<body bgcolor="#FFFFFF" text="#000000">
<h1 align="center">GB Voting </h1>
<h2 align="center">Welcome to the results page</h2>
<h2 align="center">The issue in question is:</h2>
<h1 align="center"><?php print $myrow['description']; ?></h1>

if($vote_finished>0){
print"<h3 align=\"center\"><a href=\"vote.php?$ballotid\">Vote still
running</a></h3>";
$result = mysql_query("SELECT UNIX_TIMESTAMP(end_date) AS unixdate FROM
ballot WHERE ballotid='$_GET[ballotid]'" ,$db);
$myrow = mysql_fetch_array($result);
$RealDate = date("F jS, Y", $myrow["unixdate"]);
print "<h1 align=\"center\" class=\red\">Results available on
$RealDate</h1></body></html>";
exit;
}
?>
<h3 align="center">Only confirmed votes (<?php print $totalrows; ?>) are
counted</h3>
<?php

//summary

$choices= explode(",", $myrow['choices']);

if($totalrows>0){
print"<hr size=\"1\" width=\"90%\"><table width=\"75%\" border=\"0\"
cellspacing=\"0\" cellpadding=\"3\" align=\"center\">";

for ($i=1;$i<count($choices); $i++){
$picked=trim(addslashes($choices[$i]));
$sql="SELECT * from vote WHERE choice='$picked' AND confirmed='Yes' AND
ballotid='$_GET[ballotid]'AND (status is null OR status='OK')";

$result = mysql_query($sql);
$numrows=mysql_numrows($result);

$percent=number_format(($numrows*100/$totalrows),1);
print "<tr>
<td width=\"39%\"align=\"right\"><b>$choices[$i]</b></td>
<td width=\"21%\">&nbsp;=&nbsp; <b>$numrows</b> ($percent%)</td>
<td width=\"40%\"><table width=\"100%\" border=\"0\"
cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td class=\"border\"><img src=\"redline.gif\" width=\"$percent%\"
height=\"3\"></td>
</tr>
</table></td>
</tr>";
}
print "</table>";
//end summary
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Timin Uram | last post by:
I'm not sure if this forum is the correct place to post this, but I couldn't think of any other group. I would really appreciate any help you could give me. FINAL GOAL OF MY APPLICATION:...
6
by: Tarek | last post by:
hi, May I want to know ASP or Javascript can generate a chart (pie chart) ? or other method can do that? I feel appreciate that anyone can help me ! ^^' -- Regards, Tarek ^^'
2
by: KevinGPO | last post by:
I am making a monitor program for the PC. My monitor program will grab statistics about CPU and memory every 1 or 5 seconds. Then I want to store this data so I have a history and hence be able to...
3
by: Vincenzino | last post by:
Hi, I have some problem in using SQL3 recursive queries on DB2 database system (8.1 and 8.2 UDB). I need to compute the transitive closure of a (possibly) ciclic graph using SQL3 on DB2. I MUST...
2
by: Jeff Blee | last post by:
I am hoping someone can help me. I am making a Access 97 app for a person and have run up against a problem to do with MS Graph. There is a table that has a number of data elements and a date field...
0
by: z.ghulam | last post by:
Hi, I have a line graph used to tally up the number of orders each engineer does in a week. This works well apart from 2 things: 1) If an engineer is off for a week or completes 0 orders, then...
0
by: ptkumar | last post by:
Hi All, I am using JfreeCharts. I have to generate an image(Pie Graph) in a jsp file. That jsp file image should be display into an .xls file. please help me on this. kumar
1
by: srinivasreddypn | last post by:
Hi everyone, is it possible to generate a line graph in flash by calling xml data into flash. m seeking for any reference. please help me thank u, srinvas
3
by: The Frog | last post by:
Hi guys, I have never touched really on this area before with forms and reports, and now I would like to be able to incorporate some graphs / charts for a new little app I am building, and I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.