Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

How to process data from query in PHP

$
0
0

I wanted to display data from SQL Server database in my html page. I already wrote a code that get data in PHP :

<?php 
      $serverName = "srv\SQLEXPRESS";
      $connectionInfo = array("Database" => "PROFACE", "UID"=>"username", "PWD"=>"pwd");
      $conn = sqlsrv_connect($serverName, $connectionInfo);

      if($conn) {
        echo "Connexion OK <br/>";
      } else {
        echo "La connexion NOK <br/>";
        die(print_r(sqlsrv_errors(), true));
      }

      $sql = "SELECT * 
              FROM PROFACE.dbo.SuiviProduction 
              WHERE Time_Stamp >= DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()),0)
              AND DATEPART(HOUR,Time_Stamp) = DATEPART(HOUR,GETDATE())-2";

      $params = array(1, "some data");
      $stmt = sqlsrv_query($conn, $sql, $params);
      if($stmt == false) {
        die(print_r(sqlsrv_errors(), true));
      } else {
        $data = sqlsrv_fetch_array($stmt);
        sqlsrv_free_stmt($stmt);
        sqlsrv_close($stmt);
      }
     ?>

Then I wanted to display the result of the query, so I wrote :

foreach ($data as $key => $value) {
         //echo "{$key} => {$value}";
          print_r($data);
}

What I have is this following :

Array ( [0] => DateTime Object ( [date] => 2019-11-13 08:00:00 [timezone_type] => 3 [timezone] => Europe/Paris ) [Time_Stamp] => DateTime Object ( [date] => 2019-11-13 08:00:00 [timezone_type] => 3 [timezone] => Europe/Paris ) [1] => 237 [Time_Stamp_ms] => 237 [2] => 2227 [CompteurTotalLot] => 2227 [3] => 2001 [CompteurBonnesLot] => 2001 [4] => 10 [CompteurRebutsLot] => 10 [5] => 3120227 [CompteurTotalisateur] => 3120227 )

I don't know how to process this data in order to have someting more clear.


Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>