Home > Net >  PHP/CSS - Position your data according to their status
PHP/CSS - Position your data according to their status

Time:12-31

I am displaying order numbers and their status from a mssql database

The problem is that they don't stay next to each other but go straight down.

I would like to make 3 columns on my page with all the orders scrolling and stuck to their order numbers

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/agrah.css">
    <title>AGRAH</title>
</head>
<body>
    <ul >
     <?php
            //CONNEXION ODBC SERVER//
            $dsn="";
            $user="";
            $password="";
            $conn=odbc_connect($dsn
                ,$user, $password);

            //REQUETES
            $sql = <<<EOF
                    SELECT [enc_cmd_num]
                    FROM [encaissement]
                    WHERE enc_date= '20221130'
                    EOF;

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

            while($resultrow = odbc_fetch_array($results)){ 
                echo $resultrow["enc_cmd_num"]."<br/>" ; }

                ?>

                <li>

                    <?php
            //CONNEXION ODBC SERVER//
            $dsn="Zeshop";
            $user="sa";
            $password="mrsushi";
            $conn=odbc_connect($dsn,$user, $password);

            //REQUETES
            $sql = <<<EOF
                    SELECT [enc_prepared]
                    FROM [encaissement]
                    WHERE enc_date= '20221130'
                    EOF;

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

            //CONDITION

                while($resultrow = odbc_fetch_array($results)) {
                    switch($resultrow['enc_prepared']){
                    case 0:
                        echo "<li><span>Commande en attente</span> \r\n";
                        break;
                    case 1:
                        echo "<span>Commande en cours de préparation<br/></span></li>\r\n";
                        break;
                    default: echo "<td>Unknown</td>";
                }

            }

?>

</ul>


RESULT

Thanks to all for your precious help

CodePudding user response:

Looking at the above 2 sql queries where they both return just a single field it seems likely that you could run a single SQL query that returns both columns in the recordset and iterate through that recordset just once. I cannot be certain but I believe the following ought to work

<?php
    $dsn="";
    $user="";
    $password="";
    $conn=odbc_connect( $dsn ,$user, $password );
    
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="stylesheet" type="text/css" href="css/agrah.css" />
        
        <title>AGRAH</title>
    </head>
    <body>
        <ul >
        <?php
            # combine the two queries in single query with two columns
            $sql = "SELECT [enc_cmd_num],[enc_prepared]
                FROM [encaissement]
                WHERE enc_date= '20221130'";
                
            # run the query
            $results = odbc_exec( $conn, $sql );
            
            # iterate through the recordset once
            while( $row = odbc_fetch_array( $results ) ){
            
                # fork the output based upon value of this column
                switch( $row['enc_prepared'] ){
                    case 0: $prep='<span>Commande en attente</span>'; break;
                    case 1: $prep='<span>Commande en cours de préparation</span>'; break;
                    default:$prep='unknown';break;
                }
                
                # print the `li` with content from db and calculated data from above
                printf('<li>%s - %s</li>', $row["enc_cmd_num"], $prep );
            }


        ?>
        </ul>
    </body>
</html>
  • Related