Home arrow PHP arrow Page 3 - Statistical View of Data in a Clustered Bar Chart
PHP

Statistical View of Data in a Clustered Bar Chart


In this article, Naeem shows us how to go about creating a statistical view of data, in the form of a clustered bar chart, using PHP and MySQL.  He provides a real-life scenario, along with accompanying code, to demonstrate how the job can be accomplished.

Author Info:
By: Muhammad Naeem
Rating: 4 stars4 stars4 stars4 stars4 stars / 57
December 01, 2003
TABLE OF CONTENTS:
  1. · Statistical View of Data in a Clustered Bar Chart
  2. · Database
  3. · Getting Down and Dirty
  4. · Drawing Charts
  5. · Conclusion

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials