【问题标题】:display column data in each table data在每个表数据中显示列数据
【发布时间】:2013-06-13 06:23:32
【问题描述】:
---------------------------------------------------------------------
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>

【问题讨论】:

  • @Þaw 我编辑了我的帖子,先生
  • 我不是php大师,但我认为你应该做的是在php中创建一个for循环并在其中添加&lt;td&gt;,然后从数据库中提取每个数据。
  • @HmxaMughal 会试试的,谢谢

标签: php html sql sql-server


【解决方案1】:

如果您使用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>";

【讨论】:

    【解决方案2】:

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

    $result = $mysqli->query($query);
    while ($row = $result->fetch_object()){
        echo "<tr>";
        echo "<td>" . $row->quantity . "</td>"
    ...etc...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-09
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      相关资源
      最近更新 更多