如何在PHP中循环显示所有行

时间:2019-01-23 20:16:03

标签: php

所以我在PHP循环中遇到这个问题,我似乎无法显示,它只显示第一行。我想显示所有18个地方,同时所有地方每个都有不同的计数/数据。我想我在PHP中缺少很多东西。

 //This part of code displays the names and counts the met conditions
$sql = "SELECT   b.name as brgy0,(SELECT COUNT(brgy_id) FROM tbl_fire_info where YEAR(date_of_report)=$year AND MONTH(date_of_report)=$smonth and status=1 AND brgy_id=b.barangayID) as cnt FROM tbl_barangay as b";
   $result = mysqli_query($conn, $sql);
    $row = mysqli_fetch_assoc($result); 

      $numData = $row['cnt']; 
      $brgyData = $row['brgy0'];


 //This part of code displays the data in the graph, I decided to loop it 18 times
   new Chart(document.getElementById("bar-chart-grouped"), {
      type: 'bar',
      data: {
       labels: ['<?php if(isset($_POST['submit'])){echo $haz;} ?>'], 
       datasets: [ //barangays
           <?php
             if ($result->num_rows > 0) {
               while($row = $result->fetch_assoc()) {
            ?>
               {
                 label: "<?php if(isset($_POST['submit'])){echo $brgyData;} ?>", 
                  backgroundColor: "#3e95cd",
                  data: [<?php if(isset($_POST['submit'])){echo $numData;} ?>]
               }      
           <?php
              echo ",";
              }
            }else {
                   echo "0 results";
                  }
            ?>
                ]
                  },
                   options: {
                   title: {
                   display: true,
                   text: 'Number of reports'
                          }
                        }
           });

0 个答案:

没有答案