473,486 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3292
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
2189
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
6541
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
2916
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
4140
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
2519
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
1217
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
1687
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
1792
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
4687
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
7099
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
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...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4864
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.