Statistical View of Data in a Clustered Bar Chart - Getting Down and Dirty
(Page 3 of 5 )
An HTML user interface is used to populate all of the four tables. First fill the programs and subjects tables, then populate the students table and in the final, give records to the marks table.
I shall not go into explaining how these four tables have been populated from the html forms, as I’m under the impression that this would be a trivial task. Rather, I shall focus on how the statistical view is created.
Our input HTML form and related PHP processing code has been written in such a way that it can be enhanced easily. The code snippet for the user input form is composed of three related web controls which pull the data from three tables. Here, these three controls are web control arrays:
<?php
$query = "select s.id , s.name from students as s order by s.name";
$result = mysql_query($query);
php?>
<select name= "sel_id[]" size = "10" multiple style = "background-color: #ffffe8;" >
<?php
while ($row = mysql_fetch_row($result))
echo "<option value=" . $row[0] . ">" . $row[1] . "</option>";
php?>
</select>
The remaining two web controls are also populated in the same fashion:
<?php
$query = "select p.id , p.program from programs as p order by p.program";
$result = mysql_query($query);
php?>
<select name= "sel_program_id[]" size = "5" multiple style = "background-color: #ffffe8;" >
<?php
while ($row = mysql_fetch_row($result))
echo "<option value=" . $row[0] . ">" . $row[1] . "</option>";
php?>
</select>
<?php
$query = "select s.id , s.subject from subjects as s order by s.subject";
$result = mysql_query($query);
php?>
<select name= "sel_subject_id[]" size = "5" multiple style = "background-color: #ffffe8;" >
<?php
while ($row = mysql_fetch_row($result))
echo "<option value=" . $row[0] . ">" . $row[1] . "</option>";
php?>
</select>
Also, the range of a date can be provided as an input from the same page. The code snippet will further explain this; it has been repeated twice, once for Date (From) and again for Date (To).
<?php
$months = array (1=>"January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December");
php?>
<tr><td colspan=2 align=center><table border=0>
<tr><td>Date (From)</td>
<td>
<select name="sel_day_from">
<?php
for ($i = 1; $i < 10 ; $i++)
echo "<option value=0".$i.">" . $i . "</option>";
for ($i = 10; $i < 32; $i++)
echo "<option value=".$i.">" . $i . "</option>";
php?>
</select>
<select name="sel_month_from">
<?php
for ($i = 1; $i < 10 ; $i++)
echo "<option value=0".$i.">" . $months[$i] . "</option>";
for ($i = 10; $i < 13; $i++)
echo "<option value=".$i.">" . $months[$i] . "</option>";
php?>
</select>
<?php $dt_y = intval(date(Y)); php?>
<select name="sel_year_from">
<?php
for ($i = $dt_y; $i > 2000; $i--)
echo "<option value=" . $i . ">" . $i . "</option>";
php?>
</select>
</td></tr>
This is just a simple way in which to offer more options. There is very little you have to do on the processing side. Also, a new dimension will be processed in your bar chart.
So far on our input forms, there are four criteria the user can choose from:
- student name
- subject
- program
- and range of Date
Our database is now ready to be subjected to operations under drawing bar charts.
Next: Drawing Charts >>
More PHP Articles
More By Muhammad Naeem