title: Fetching data from database to bar graph with php
body: <p>I have a graph with this kind of data format</p>
  
  <p>data:[station_id1,station_id2,station_id3]    x axis
  date:[total_station1,total_station2,total_station3]  y axis</p>
  
  <p>however i want to fetch the data from my database table which have list of all the station_id and their corresponding data. i want to all the distinct station id for x axis and correspondence total sum of each id for y axis.</p>
  
  <p>below is my code </p>
  
  <pre><code>data: [&lt;?php
  $q = "SELECT DISTINCT  outletid,amount FROM " . TBL_SALES_LOGS;
  $result = $database-&gt;query($q);
  while ($row = $result-&gt;fetch_assoc()) {
      // $outletname = $row['title'];
      $outlet_id = $row['outletid'];
      $amount = $row['amount'];
      ?&gt;
      &lt;?php echo " $outlet_id"; ?&gt;,
  &lt;?php } ?&gt; ]
  
  data: [&lt;?php
  $qsum3 = "SELECT  SUM(amount) AS totalsum FROM " . TBL_SALES_LOGS . " WHERE outletid ='$outlet_id' and fueltype='AGO'";
  $qresult3 = $database-&gt;query($qsum3);
  while ($rowq3 = $qresult3-&gt;fetch_assoc()) {
      $tot3 = $rowq3['totalsum'];
      ?&gt;'&lt;?php echo $tot3; ?&gt;',&lt;?php } ?&gt;]
  </code></pre>
  
  <p>After running it, the output is:</p>
  
  <p>data: [ 520718, 567329, ] data: ['5000',]</p>
  
  <p>and what i want is data 1 to be distinct station id and data2 should be sum of each distinct station id to correspond with data1</p>