Home > Enterprise >  Doing PHP word processing
Doing PHP word processing

Time:12-21

I have retrieved data from a MSSQL server table. I was able to display them thanks to a query. I would like to be able to modify these data without touching the table

For example the values which are in 1 for enc_paye would display ("Order in preparation) and enc_prepared (Order ready)

Also I would like to know if it is possible to remove the text from the table and only recover the data.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Espace Client</title>
</head>
<body>
        <center><div >
     <?php
            //CONNEXION ODBC SERVER//
            $dsn="";
            $user="";
            $password="";
            $conn=odbc_connect($dsn,$user, $password);

            //REQUETES
            $sql = <<<EOF
                    SELECT top 10 [enc_cmd_num], [enc_paye], enc_prepared, enc_emporte, enc_heure_fab_fin, enc_ext_ref
                    FROM [encaissement]
                    WHERE enc_date= '20221130'
                    EOF;

            $results = odbc_exec($conn,$sql);
            odbc_result_all($results);


            //CONDITION
            echo "<table>";
                while($resultrow = odbc_fetch_array($results)) {
                    switch($resultrow['enc_paye']){
                    case 0:
                        echo "Commande en attente paiement";
                        break;
                    case 1:
                        echo "Commande en cours de préparation";
                        break;
                    default: echo "<td>Unknown</td>";
                }

            }
            echo "</table>";


?>
</div></center>
   








enter image description here

CodePudding user response:

It looks like you may be storing status information about the order in different columns. I would suggest just using one column with different status numbers.

Perhaps:

0 - "Order received"
1 - "Order in preparation"
2 - "Order ready"
3 - "Order dispatched"

You can then use a switch statement in PHP to select between the text options

For example:

echo "<table>";
while($resultrow = odbc_fetch_array($results)) {
    echo "<tr>";
    switch($resultrow['enc_paye']){
        case 0:
            echo "<td>Order received</td>";
            break;
        case 1:
            echo "<td>Order in preparation</td>";
            break;
        case 2:
            echo "<td>Order completed</td>";
            break;
        case 3:
            echo "<td>Order dispatched</td>";
            break;
        default: echo "<td>Unknown</td>";
    }
    // print some other fields in table data fields
   echo "</tr>";
}
echo "</table>";

The odbc_result_all function has been deprecated, so ideally you shouldn't use it.

** Edited following comments from @Adyson **

CodePudding user response:

You can fetch your ODBC-result as an array:

$ODBCcontent = odbc_fetch_array($results);
  • Related