使用SQL字段在表中创建链接

时间:2014-03-31 13:08:58

标签: php sql

我有以下代码用于在表格中显示结果。我需要一些帮助从Tickets表中获取ID并在超链接的末尾使用它,例如" .PHP ID = 7&#34?; 我一直在阅读这方面的教程,但事情似乎并没有发生在我身上。 提前谢谢。

<table class="table">
    <tbody><tr><th>ID</th><th>Site Name</th><th>Title</th><th>Description</th><th>Quick Description</th><th>Contact</th><th>Status</th></tr>
<?php
$con = mysqli_connect(*credentials*);
if (!$con)
  {
  die('Could not connect: ' . mysqli_error());
  }

$result = mysqli_query($con, "SELECT * FROM Tickets WHERE Status='Open' AND Active='active'");

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><a href='//PHP/displayticket.php?id=$ID'>" . $row['ID'] . "</a></td>";
  echo "<td>" . $row['SiteName'] . "</td>";
  echo "<td>" . $row['Title'] . "</td>";
  echo "<td>" . $row['Description'] . "</td>";
  echo "<td>" . $row['quickdesc'] . "</td>";
  echo "<td>" . $row['Contact'] . "</td>";
  echo "<td>" . $row['Status'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?>  

2 个答案:

答案 0 :(得分:2)

echo "<td><a href='//PHP/displayticket.php?id={$row['ID']}'>" . $row['ID'] . "</a></td>";
你是说这个意思吗?或者我不理解你的问题?

答案 1 :(得分:1)

替换:

while($row = mysqli_fetch_array($result))

使用:

$rows = mysqli_fetch_array($result, MYSQLI_ASSOC);
foreach ( $rows AS $row )