search

Home  >  Q&A  >  body text

Engage in PHP-based word processing

<p>I have retrieved data from an MSSQL server table. Thanks to the query I am able to display them. I want to be able to modify this data without touching the table</p> <p>For example, a value of 1 for enc_paye would display ("Order in preparation") and enc_prepared (Order ready)</p> <p>I would also like to know if it is possible to delete the text from the table and recover only the data. </p> <pre class="brush:php;toolbar:false;"><!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 class="Informations"> <?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></pre>
P粉590929392P粉590929392491 days ago525

reply all(2)I'll reply

  • P粉139351297

    P粉1393512972023-09-03 17:45:51

    You can get the ODBC results as an array:

    $ODBCcontent = odbc_fetch_array($results);

    reply
    0
  • P粉757640504

    P粉7576405042023-09-03 14:22:43

    It seems that you may be storing status information about the order in different columns. I recommend just using one column with different status numbers.

    Maybe:

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

    You can then use a switch statement in PHP to choose between 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>";

    odbc_result_all function is deprecated, so ideally you should not use it.

    ** Edited the following comment by @Adyson **

    reply
    0
  • Cancelreply