簡體   English   中英

如何從數據庫獲取傳遞的值數據並使用php顯示在html表中

[英]how to get the passed value data from the database and show in a html table using php

我有數據庫,有名為supplier表。它包含不同的列,如region,country,9xx,10xx

我在下拉列表中獲取9xx,10xx列。當用戶選擇其中的任何一個時,選擇的值將轉到執行mysql查詢的頁面,然后結果顯示在html表中。

問題是我沒有從數據庫獲取傳遞值的記錄(即Supplierid:10xx或9xx),請參閱我的代碼

    <?php

    $dbHost = 'localhost'; // usually localhost
    $dbUsername = 'xxxxxxxxx';
    $dbPassword = 'xxxxxxxxxx';
    $dbDatabase = 'xxxxxxxxxxx';
    $db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
    mysql_select_db ($dbDatabase, $db) or die("Could not select database.");

    $supplierid = $_GET['supplier_id'];
    //supplierid is 10xx or 9xx

    $sql = "SELECT region,country,$supplierid FROM supplierprice order by country ASC ";


   $sql_select = mysql_query($sql); 

    while($rows=mysql_fetch_array($sql_select))
    {


    if($alt == 1)
            {
               echo '<tr class="alt">';
               $alt = 0;
            }
            else
            {
               echo '<tr>';
               $alt = 1;
            }

    echo '  

                <td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '.$rows["id"].'">'.$rows["region"].'</td>   
                <td id="CPH_GridView1_country " style="width:101px" class="edit country '.$rows["id"].'">'.$rows["country"].'</td>  

                <td id="CPH_GridView1_mnc " style="width:51px" class="edit mnc '.$rows["id"].'">'.$rows[$supplierid].'</td> 

                </tr>';

    }

     ?>

您實際上是在混合HTML和PHP。 它們可以一起使用,但不能互相使用,您應該使用以下代碼:

只需刪除以下代碼:

echo '  

>                 <td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth
> '.$rows["id"].'">'.$rows["region"].'</td>   
>                 <td id="CPH_GridView1_country " style="width:101px" class="edit country '.$rows["id"].'">'.$rows["country"].'</td>  
> 
>                 <td id="CPH_GridView1_mnc " style="width:51px" class="edit mnc '.$rows["id"].'">'.$rows[$supplierid].'</td> 
> 
> 
>           </tr>';
> 
>     }
> 
>      ?>

並在其位置添加以下代碼

<td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '<?php.$rows["id"] ?>.'"> <?     php echo $row["region"]; ?> </td>                                                 
<td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '<?php.$rows["id"] ?>.'"> <? php echo $row["country"]; ?> </td>     
<td id="CPH_GridView1_billingmonth " style="width:40px" class="edit billingmonth '<?php.$rows["id"] ?>.'"> <?php echo $row["id"]; ?> </td>

    <?php

        }

         ?>

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM