Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    php pie chart from DB

    Hi, I am trying to create a pie chart for diff browser versions
    Like MSIE 9.0. FireFox etc

    I have the chart code working, just looking for the best way
    to get data from MySQL

    example, this works fine
    <img src="PieChart.php?data=1*3*5*10&label=MSIE 9.0*MSIE 8.0*MSIE 7.0*MSIE 6.0 />

    what would be the best way to count and label results for chart?

    Update works fine now
    PHP Code:

    $result1 
    mysql_query("SELECT * FROM mytable WHERE ua LIKE '%MSIE 9.0%'"); 
    $E9 mysql_num_rows($result1);

    $result2 mysql_query("SELECT * FROM mytable WHERE ua LIKE '%MSIE 6.0%'"); 
    $E6 mysql_num_rows($result2); // etc.....

    $data"$E9*$E6";
    $label "MSIE 9.0*MSIE 6.0"
    Thanks
    Sonny
    Last edited by sonny; 11-25-2012 at 08:19 AM.

  • #2
    Banned
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is better that you put all the browser type into an array first and loop through array to pull out result:
    PHP Code:
    $arr=array("Firefox","MSIE");
    $data "";
    $label "";
    for(var 
    $i=0;$<count($arr);$i++)
    {
       
    $result mysql_query("SELECT * FROM mytable WHERE ua LIKE '%".$arr[$i]."'");  
      
    $num mysql_num_rows($result); 
      
    $data =  $num.(($=0)?"":"*");
      
    $label =  $arr[$i].(($=0)?"":"*");

    By the way here is an great interactive chart for PHP:

    http://demo.koolphp.net/Examples/Koo...hart/index.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •