0
---------------------------------------------------------------------
Quantity  |   Unit  |  Detials of Items |  ISSUED DATE  |  RETURNED |
          |         |                   |               |           |
---------------------------------------------------------------------
tbl col 1 |tbl col2 | tbl col2          |  tbl col 3    | tbl col4  |
---------------------------------------------------------------------

假设我在数据库中有一个有 4 列的表

那是我网站上的表格

我将如何在每个表数据中显示我的表列数据?

请有任何建议

到目前为止,我只有这些代码,因为我是 php 新手,我只使用宏媒体作为界面

$myServer = "server";
 $myUser = "user";
 $myPass = "password";
 $myDB = "mssqldb"; 

 //connection to the database
 $dbhandle = mssql_connect($myServer, $myUser, $myPass)
     or die("Couldn't connect to SQL Server on $myServer"); 

 //select a database to work with
      $selected = mssql_select_db($myDB, $dbhandle)
          or die("Couldn't open database $myDB"); 

 //declare the SQL statement that will query the database
     $query = "SELECT eidnumber ";
     $query .= "FROM tablename ";

<table width="935" height="102" border="1">
      <tr>
        <th width="89" rowspan="2" scope="col">Quantity</th>
        <th width="87" rowspan="2" scope="col">Unit</th>
        <th width="137" rowspan="2" scope="col">Details of Item(s) Accounted </th>
        <th width="221" rowspan="2" scope="col">ISSUED DATE </th>
        <th height="51" colspan="3" scope="col">RETURNED</th>
        <th width="254" rowspan="2" scope="col">
    <p>REMARKS</p>    </th>
      </tr>
      <tr>
        <th width="24" height="39" scope="col">C</th>
        <th width="18" scope="col">X</th>
        <th width="53" scope="col">DATE</th>
      </tr>
    </table>
    <table width="935" border="1">
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
      <tr>
        <td width="90">&nbsp;</td>
        <td width="86">&nbsp;</td>
        <td width="137">&nbsp;</td>
        <td width="221">&nbsp;</td>
        <td width="24">&nbsp;</td>
        <td width="17">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="253">&nbsp;</td>
      </tr>
    </table>
4

2 回答 2

5

如果您使用的是PDO,这是一种更好的方法:

echo "<table>";
$sql = $this->db->query("SELECT * FROM YOUR_TABLE");
while($row = $sql->fetch(PDO::FETCH_ASSOC))
{
    echo "
    <tr>
        <td>". $row['quantity'] ."</td>
        <td>". $row['unit'] ."</td>
        <td>". $row['details'] ."</td>
        <td>". $row['issued_date'] ."</td>
        <td>". $row['returned'] ."</td>
    </tr>
    ";
}
echo "</table>";

或者,如果您是mysql_已弃用的函数:

echo "<table>";
$sql = mysql_query("SELECT * FROM YOUR_TABLE");
while($row = mysql_fetch_assoc($sql))
{
    echo "
    <tr>
        <td>". $row['quantity'] ."</td>
        <td>". $row['unit'] ."</td>
        <td>". $row['details'] ."</td>
        <td>". $row['issued_date'] ."</td>
        <td>". $row['returned'] ."</td>
    </tr>
    ";
}
echo "/<table>";
于 2013-06-13T06:32:34.317 回答
3

除了上面的答案,你还可以使用mysqli。这是一个例子:

$result = $mysqli->query($query);
while ($row = $result->fetch_object()){
    echo "<tr>";
    echo "<td>" . $row->quantity . "</td>"
...etc...
}
于 2013-06-13T06:39:28.200 回答