Forum Discussion

MouradSahbeni's avatar
MouradSahbeni
Copper Contributor
Jun 11, 2022

problem displaying data in php form

Hello everyone,
I am creating a page where I want to display a table containing the data of a sql server 2017 table. The problem is I cannot display them.. Can anyone help me solve this problem?

here is my php code

 

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">


    <title>Home</title>
</head>

<body>
    <h1>Liste Collisage</h1>



    <nav class="navbar navbar-light bg-light">
        <a class="navbar-brand">
            <pre>Delivery note Nr.                    C20220019           Crings Lieferung                                                                                                         <?php echo "" . date("Y/m/d") . "<br>";?></pre>
            <a>
    </nav>

    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <table id="dest_data" class="table table-striped table-bordered" style="width:100%">
                    <thead>
                        <tr>
                            <th>Code à Barres</th>
                            <th>Article Name</th>
                            <th>Désignation</th>
                            <th>Quantity par Size</th>
                            <th>Quantité Totale</th>
                            <th>Article Number</th>
                            <th>CRINGS Number</th>
                            <th>Order Number</th>
                            <th>Order</th>
                            <th>Box NR</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php

error_reporting(E_ALL);

        ini_set('display_errors', '1');



$serverName = "SRV"; //serverName\instanceName
$connectionInfo = array( "Database"=>"phils", "UID"=>"sa", "PWD"=>"Passw0rd");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connexion établie.<br />";
}else{
     echo "La connexion n'a pu être établie.<br />";
     die( print_r( sqlsrv_errors(), true));
}
function ReadData()
{
    try
    {
        $conn = OpenConnection();
        $tsql = "SELECT Code à Barres,
         Article,
         Désignation,
         Quantité par Unité,
         Quantité Totale,
         Groupe2,
         Propriété3,
         OF,
         NUMORDRE,
         NUMPALETTE
          FROM phils.Ligne Livraison Client réf";
        $getProducts = sqlsrv_query($conn, $tsql);
        if ($getProducts == FALSE)
            die(FormatErrors(sqlsrv_errors(),TRUE));
        $productCount = 0;
        while($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC))
        {
    echo "Code à Barres: ".$row[0]."\n";  
     echo "Article: ".$row[1]."\n";  
     echo "Désignation: ".$row[2]."\n";  
     echo "Quantité par Unité: ".$row[3]."\n";  
     echo "Quantité Totale: ".$row[4]."\n";
     echo "Groupe2: ".$row[5]."\n";  
     echo "Propriété3: ".$row[6]."\n";
     echo "OF: ".$row[7]."\n";  
     echo "NUMORDRE: ".$row[8]."\n";
     echo "NUMPALETTE: ".$row[9]."\n";
     echo "-----------------\n";  
            $productCount++;
        }
        sqlsrv_free_stmt($getProducts);
        sqlsrv_close($conn);
    }
    catch(Exception $e)
    {
        echo("Error!");
    }
}
                        ?>


                    </tbody>

                </table>
            </div>
        </div>
    </div>


    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
    <script>
    $('#dest_data').DataTable();
    </script>

</body>

</html>

 

1 Reply

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    MouradSahbeni , your SQL statement is more the a bit wrong and will cause errors. If an object name contains special characters, even simple spaces, you must set them in brackets, see below.

    Better avoid spaces in object name.

     

    $tsql = "SELECT [Code à Barres],
               Article,
               Désignation,
               [Quantité par Unité],
               [Quantité Totale],
               Groupe2,
               Propriété3,
               OF,
               NUMORDRE,
               NUMPALETTE
             FROM phils.[Ligne Livraison Client réf]";

Resources