使用if(isset)和连接表调用id的问题

时间:2017-06-07 22:56:59

标签: php mysql isset

我是一个PHP新手,我一整天都在努力解决这个问题,但无济于事,我提供的代码可以获得一个' id'从一个页面打开一个新页面,我使用if(isset)_GET方法来调用新页面中的id,同时想要连接两个表来从中选择数据并在同一页面上显示。我写了下面的代码

如果有人告诉我错误的地方以及如何做到这一点,我将不胜感激

    <?php
session_start();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">

<body class="home">
    <!-- Intro -->
    <div class="container text-center">

    </div>
    <!-- /Intro-->              
                        <?php

                        require_once 'includes/connect.php';


                        if(isset($_GET['id'])) {

                        $full_name = $_GET['id'];

                            $select_query = "SELECT quoteform.quote_id, quoteform.gender, quoteform.feedback_bad, quoteform.feedback_ok, quoteform.size, quoteform.accessory,quoteform.quantity, quoteform.full_name, quoteform.phone_number, quoteform.email, quoteform.location, quoteform.quote_date,quoteform.order_number, price_products.price_withfabric FROM quoteform, price_products WHERE qouteform.feedback_bad = price_products.product_name OR quoteform.feedback_ok = price_products.product_name AND full_name='$full_name' LIMIT 1";

                        $run_query = mysqli_query($con, $select_query);                 
                        ?>      

    <!-- Highlights - jumbotron -order -->
    <div class="jumbotron-order">
        <div class="container">
        <?php  
                          if(mysqli_num_rows($run_query) > 0)  
                          {  
                               while($row = mysqli_fetch_array($run_query))  
                               {  
                          ?>
                <h3 class="text-center thin"> - Order Form - </h3></br>
                <h4 class=" thin"> Hello <?php echo $row["full_name"];?></h4></br>
                <h4 class=" thin"> Order No. <?php echo $row["order_name"];?> </h4>

                <div class="row">
                    <div class="col-md-8 col-sm-8">                     
                        <div class=" panel">
                                <table class="table">
                                      <tr>
                                        <th scope="row"> Outfit</th>
                                        <th><?php echo $row["feedback_bad"];?> </th>
                                      </tr>
                                      <tr>
                                        <th scope="row"> Size</th>
                                        <th><?php echo $row["size"];?></th>
                                      </tr>
                                      <tr>
                                        <th scope="row"> Price </th>
                                        <th> <?php echo $quantity; ?> X <?php echo $price_withfabric; ?> </th>
                                        <th> = Amount</th>
                                      </tr>
                                      <tr>
                                        <th scope="row"> Accessory <<- Add More Button ->> </th>

                                      </tr>
                                      <tr>
                                        <td scope="row"> <?php echo $accessory; ?> </td>
                                        <th> Qty X price = </th>
                                        <th> = Amount</th>
                                      </tr>
                                      <tr>
                                        <th scope="row"> Click to select Service Charge </th>
                                        <th> Display Service Name </th>
                                        <th> = Amount</th>
                                      </tr>
                                      <tr>
                                        <th scope="row"> Click to select Delivery </th>
                                        <th> Display Delivery </th>
                                        <th> = Amount</th>
                                      </tr>
                                      <tr>
                                        <th scope="row">  </th>
                                        <th scope="row"> Total </th>
                                        <th> Display Amount Here!!!</th>
                                      </tr>
                                      <tr>
                                        <th scope="row"> Do you have a Coupon Code?  </th>
                                        <th scope="row"> coupon input space </th>
                                        <th> The amount to be deducted from Total</th>
                                      </tr>
                                      <tr>
                                        <th scope="row">  </th>
                                        <th scope="row"> Amount to be Charged </th>
                                        <th> Display Amount Here!!!</th>
                                      </tr>
                                </table>
                                <div class="text-center"><button class="btn btn-success btn-lg">Preview and Pay</button> <button class="btn btn-danger btn-lg">Cancel Order</button></div>
                        </div>
                    </div>
                </div>      
            <!-- /row  -->
        <?php } } ?> 
        </div>
    </div>
<?php }  ?> 

2 个答案:

答案 0 :(得分:-1)

我们可以使用一些代码,但看起来您正在执行查询,将该查询的结果存储在变量中,然后将该变量传递给mysqli_num_rows。查询可能失败了。当mysqli_query()失败时,它返回布尔值FALSE,而不是mysqli_result的实例。输出查询,因为它发送到MySQL&amp;我打赌看起来有些不对劲。

答案 1 :(得分:-1)

更改此行:

if(mysqli_num_rows($run_query) > 0)  

对此:

if(!empty($run_query) && mysqli_num_rows($run_query) > 0)  

这样,如果$run_query的失败查询值为false,则不会打印数据。

现在你可能想要做一些事情 else 如果那个查询失败了,那么就像这样进行另一次检查:

if(empty($run_query)) {
    // do something here if the query failed
}