PHP/CSS -根据数据状态定位数据

1l5u6lss  于 2023-01-01  发布在  PHP
关注(0)|答案(1)|浏览(94)

我正在显示mssql数据库中的订单号及其状态
问题是它们并不是紧挨着的而是直接向下的。
我想在我的网页上与所有的订单滚动3列,并坚持自己的订单编号

<!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 class="col">
     <?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>

感谢大家的宝贵帮助

raogr8fs

raogr8fs1#

看看上面的两个SQL查询,它们都只返回一个字段,看起来你可以运行一个SQL查询,返回记录集中的两列,并在记录集中迭代一次。

<?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 class="col">
        <?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>

相关问题