如何在点击产品时显示产品信息

时间:2017-04-09 20:14:10

标签: php mysql sorting

我一直在解决在用户点击产品时如何显示产品信息的问题。 到目前为止,我已经设置了产品页面和排序功能,其他一切我试过打破它。

<?php
        require_once('includes/database.php');
        $page_title = 'Classic Models | Products';
    ?>`enter code here`
    <?php include('includes/header.html.php'); ?>

     <?php 

    $sort = isset($_GET['sort']) ? $_GET['sort'] : 'Name';


    $sql= "SELECT productName, productDescription, buyPrice
    FROM `Products`
    ORDER BY $sort";

    $result = mysqli_query($db, $sql);

    // get the sort order from the url


    if(mysqli_num_rows($result)){
        //echo var_dump($result);
        echo '<table>';
        echo '<tr>
                <th><a href="?sort=ProductName">Product</a></th>
                <th>ProductDesription</th>
                <th><a href="?sort=BuyPrice">Price</a></th>
            </tr>';



        while($row = mysqli_fetch_array($result)){
        //'<pre>'. var_dump($row). '</pre>'; to show the loop worked
        //echo '<li>'. $row['productName'] . $row['productDescription'] . $row['buyPrice'] . '</li>' ; 

             //to get my products to show in a table.
    echo
                "<tr>
                  <td>{$row['productName']}</td>
                  <td>{$row['productDescription']}</td>
                  <td>{$row['buyPrice']}</td>



                </tr>";
        } 

        echo '</table>';

        }else{
            echo "Results not found";
    }




    //my footer 
    ?>
    <?php include('includes/footer.html.php'); ?>

0 个答案:

没有答案