0

I'm creating a Library management system using PHP 7 and MySQL. I want to represent the number of books that belong to a specific category like mathematics, social sciences etc. However, I can't figure out as to how I can get the number of books that belong to a specific category. I'm trying to implement the result in Google Charts as a pie chart but I cannot get any output. Below is the code that I made:

<?php
include "header.php";
include "connection.php"

 ?>
        <!-- page content area main -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="title_left">
                        <h3>Category Charts</h3>
                    </div>


                </div>

                <div class="clearfix"></div>
                <div class="row" style="min-height:500px">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>Category Charts</h2>

                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">

                              <html>
<head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript">
    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {

      var data = google.visualization.arrayToDataTable([
        ['Category', 'Percentage and count'],
        <?php
         $languages=mysqli_query($link, "SELECT COUNT (Books_Category) as languagenum FROM books WHERE Books_Category LIKE 'Languages%'");
         $es=mysqli_query($link, "SELECT COUNT(Books_Category) FROM books WHERE Books_Category LIKE 'Experimental Sciences%'");
         $maths=mysqli_query($link, "SELECT COUNT(Books_Category) FROM books WHERE Books_Category LIKE 'Mathematics%'");
         $ss=mysqli_query($link, "SELECT COUNT(Books_Category) FROM books WHERE Books_Category LIKE 'Social Sciences'");
         $arts=mysqli_query($link, "SELECT COUNT(Books_Category) FROM books WHERE Books_Category LIKE 'Arts%'");
         while ($result = mysqli_fetch_assoc($languages)) {
            echo"['".Languages."',".$languages."],";
          }
          while ($result = mysqli_fetch_assoc($es)) {
            echo"['".ExperimentalSciences."',".$es."],";
          }
          while ($result = mysqli_fetch_assoc($maths)) {
            echo"['".Mathematics."',".$maths."],";
          }
          while ($result = mysqli_fetch_assoc($ss)) {
            echo"['".SocialSciences."',".$ss."],";
          }
          while ($result = mysqli_fetch_assoc($arts)) {
            echo"['".Arts."',".$arts."],";
          }
         ?>

      ]);

      var options = {
        title: 'Book category chart'
      };

      var chart = new google.visualization.PieChart(document.getElementById('piechart'));

      chart.draw(data, options);
    }
  </script>
</div>
</div>
</div>
</div>
</div>
</div>

</head>
<body>
  <div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>

<?php
include "footer.php"
 ?>

0 Answers0