0

誰でも助けることができますか?

ばかげている場合は申し訳ありませんが、私はこれに非常に慣れていないため、自分が何をしているのか本当にわかりません...

php を使用して mysql データベースからデータを取得するテーブルを生成しましたが、(すべての行の) 最後にリンクを含む追加の列を配置したいと考えています。リンクは、そのエントリの詳細へのリンクになります。

テーブルを表示するコードは次のとおりです。

$result = mysql_query("SELECT * FROM orders");

echo "<table border='5'>
<tr>
<th>order_no</th>
<th>ord_date</th>
<th>est_completion_date</th>
<th>status</th>
<th>invoice_date</th>
<th>inv_amount</th>
<th>name</th>
<th>fName</th>
<th>lName</th>
</tr>";

// -- Use 'while' to check each row in $result in turn:
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['order_no'] . "</td>";
  echo "<td>" . $row['ord_date'] . "</td>";
  echo "<td>" . $row['est_completion_date'] . "</td>";
  echo "<td>" . $row['status'] . "</td>";
  echo "<td>" . $row['invoice_date'] . "</td>";
  echo "<td>" . $row['inv_amount'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['fName'] . "</td>";
  echo "<td>" . $row['lName'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

何度も言いますが初心者です。基本的に、(上記のコードを使用して) mysql クエリの結果を表示する html テーブルを作成することにかなり満足しています。ただし、他のテーブルにリンクするには、ユーザーが行/セルをクリックできるようにする必要があります。

どんな助けでも大歓迎です...

4

2 に答える 2

1
echo "<table border='5'>
<tr>
<th>order_no</th>
<th>ord_date</th>
<th>est_completion_date</th>
<th>status</th>
<th>invoice_date</th>
<th>inv_amount</th>
<th>name</th>
<th>fName</th>
<th>lName</th>
<!-- extra column here -->
<th>&nbsp;</th>
</tr>";

while($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['order_no'] . "</td>";
    echo "<td>" . $row['ord_date'] . "</td>";
    echo "<td>" . $row['est_completion_date'] . "</td>";
    echo "<td>" . $row['status'] . "</td>";
    echo "<td>" . $row['invoice_date'] . "</td>";
    echo "<td>" . $row['inv_amount'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['fName'] . "</td>";
    echo "<td>" . $row['lName'] . "</td>";
    // add link here
    echo "<td><a href=''>link</a></td>";
    echo "</tr>";
}

注意:関数の使用を停止する必要がありmysql_*ます。それらは廃止されています。代わりにPDO (PHP 5.1 以降でサポート) またはmysqli (PHP 4.1 以降でサポート) を使用してください。どちらを使用すればよいかわからない場合は、この記事をお読みください

于 2012-08-23T16:52:43.163 に答える
0

これを試して。列を追加します。別のページ「view_more_details.php」にリンクします。行を一意に識別するには、このリンクで一意の ID を渡します。ここで order_no を渡しました。「view_more_details.php」ページでは、$_GET['key'] を使用してこの値を選択できます。

$result = mysql_query("SELECT * FROM orders");

echo "<table border='5'>
<tr>
<th>order_no</th>
<th>ord_date</th>
<th>est_completion_date</th>
<th>status</th>
<th>invoice_date</th>
<th>inv_amount</th>
<th>name</th>
<th>fName</th>
<th>lName</th>
<th>&nbsp;</th>
</tr>";

// -- Use 'while' to check each row in $result in turn:
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['order_no'] . "</td>";
  echo "<td>" . $row['ord_date'] . "</td>";
  echo "<td>" . $row['est_completion_date'] . "</td>";
  echo "<td>" . $row['status'] . "</td>";
  echo "<td>" . $row['invoice_date'] . "</td>";
  echo "<td>" . $row['inv_amount'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['fName'] . "</td>";
  echo "<td>" . $row['lName'] . "</td>";
  echo "<td>" . "<a href="view_more_details.php?key=$row['order_no']">View More</a>" . "</td>";
  echo "</tr>";
  }
echo "</table>";
于 2012-08-23T17:14:38.433 に答える