想从MySql数据库中获取数据并在Html表中显示数据

我试图从数据库中获取值,并在HTML表中显示'ref_id' em>的所有值。 当我使用echo命令标题时,显示但没有值提取并显示在窗体上:

<?php

include "header.php";
include "db.php";

$supplier = $_POST['ref_id'];

$query = "select farm from farms where id = $supplier";

$run = mysqli_query($con, $query);

while ($row = mysqli_fetch_array($run)) {

    $url = $row['farm'];

}

$query1 = "select * from transactions where ref_id = $supplier";

$run1 = mysqli_query($con, $query1);

?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
    table,
    th,
    td,
    div {
        border: 1px solid black;
        border-collapse: collapse;
    }
    </style>
    <div class="page-content">
        <div class="row-fluid">
            <div class="span12">
                <table id="bill" style="width: 501px">
                    <tbody>
                        <tr>
                            <td colspan=3 align="center">Priv balances</td>
                            <td colspan=2 align="center">
                                </br<</td> <td colspan=2 align="center">(sale)</td>
                        </tr>
                        <tr rowspan=2>
                            <td rowspan=2 align="center">Date</td>
                            <td rowspan=2 align="center">Shift</td>
                            <td rowspan=2 colspan=2 align="center">
                                <table width=100%>
                                    <tr>
                                        <td colspan=100% align="center">
                                            Particular
                                        </td>
                                    <tr>
                                        <td colspan=70% align="center">
                                            Mun(s)
                                        </td>
                                        <td colspan=30% align="center">
                                            Kg(s)
                                        </td>
                                    </tr>
                        </tr>
                </table>
                </td>
                <td rowspan=2 align="center">rate</td>
                <td rowspan=2 colspan=2 align="center">Amount</td>
                </tr>
                </tbody>
                <tbody>
                    <?php $numberofrow = 20;?>
                    <?php while ($row = mysqli_fetch_array($run1)) {
    // Before we close out of PHP, lets define all of our variables so they are easier to remember and work with, // you can skip this though if you just want to directly reference each row. $date=$ row[
    'datetime'];
$shift = $row['milk_type'];
$mann = $row['quantity'];
$kg = $row['kg'];
$amount = $row['total_amount']; // Now for each looped row echo "<tr><td>".$date. "</td><td>".$shift. "</td><td>".$mann. "</td>   <td>".$kg.
"</td><td>" . $amount . "</td></tr>";} // End our while loop ?>
                    <?php// }?>
                    <tr colspan=7 rowspan=2>
                        <td align="left">Total Milk</td>
                        <td align="left">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                    </tr>
                    <tr colspan=7 rowspan=2>
                        <td align="left">Bandi</td>
                        <td align="left">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                        <td align="right">&nbsp;</td>
                    </tr>
                </tbody>
                <tbody>
                    <tr colspan=7>
                        <td colspan=2 rowspan=7>
                            <div>
                                <div id="span1">Date</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">Total</div>
                            </div>
                        </td>
                        <td colspan=2 rowspan=7>
                            <div>
                                <div id="span1">Payment</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">&nbsp;</div>
                                <div id="span2">77000</div>
                            </div>
                        </td>
                        <td colspan=3 rowspan=8>
                            <table border="0" width=100%>
                                <tr>
                                    <td>total amount</td>
                                    <td>65550</td>
                                </tr>
                                <tr>
                                    <td>Less Commision</td>
                                    <td>
                                        </br>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Less Fare</td>
                                    <td>
                                        </br>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Gross Bill</td>
                                    <td>
                                        </br>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Add Priv Balance</td>
                                    <td>
                                        </br>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        </br>
                                    </td>
                                    <td>
                                        </br>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Less Purchase Milk</td>
                                    <td>
                                        </br>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Net Bill</td>
                                    <td>
                                        </br>
                                    </td>
                                </tr>
                            </table>
                    </tr>
                </tbody>
                </table>
            </div>
            <!--/.span-->
        </div>
        <!--/.row-fluid-->
    </div>
    <!--/.page-content-->
</head>

</html>
<?php include "footer.php";?>
<?php
    $str = mysql_query("select farm from farms where id = $supplier");

    echo "<table>";
        echo "<th></th>";
        while ($res = mysql_fetch_array($str)) {
            echo "<tr></tr>";
        }
    echo "</table>";
?>

The line:

$query = "select farm from farms where id = $supplier";

Should look like this:

$query = "select farm from farms where id =".$supplier;

$supplier is a PHP variable and should not be in the quotes.

As I view above code I saw some spaces between $ row[] which i have been removed and echo command written in the comment section.

I hope this code will help you

<?php 

while($row=mysqli_fetch_array($run1)){ 

 $date=$row['datetime']; 
$shift=$row['milk_type']; 
$mann=$row['quantity']; 
$kg=$row['kg']; 
$amount=$row['total_amount']; // Now for each looped row 

echo "<tr><td>".$date. "</td><td>".$shift. "</td><td>".$mann. "</td><td>".$kg."</td><td>".$amount. "</td></tr>"; 
} 
// End our while loop ?>