【问题标题】:Make the content of td table linkable使 td 表的内容可链接
【发布时间】:2016-02-16 01:17:54
【问题描述】:

请有人查看此代码并告诉我如何获取可点击的<td> 表的内容?

<?php
    include 'database.php';
    $pdo = Database::connect();
    $sql = 'SELECT * FROM products ORDER BY product_id DESC';
    foreach ($pdo->query($sql) as $row) {
        echo '<tr>';
        echo '<td>'. $row['cat_id']        . '</td>';
        echo '<td>'. $row['brand_id']      . '</td>';
        echo '<td>'. $row['product_title'] . '</td>';
        echo '<td>'. $row['product_img1']  . '</td>'; 
        echo '</tr>';
    }
    Database::disconnect();
?>

我想要通过示例$row['brand_id'] 制作一个重定向到品牌详细信息的链接。

【问题讨论】:

  • 只需使用锚点,创建另一个页面,如details.php,在href 属性中回显它,最简单的是:href="detail.php?id=&lt;echo the brand id here&gt;"。从该详细信息页面中,只需使用该 ID 来选择您选择的特定行,之后您将不得不自己编写代码
  • 我的问题是这个 echo '' .$row['brand_id']。 '';我一直试图把它放在
  • 没问题,你还没试过。只需在您的字符串中添加 HTML 锚点

标签: php html variables html-table


【解决方案1】:

您的 TD 中必须有一个超链接。

echo '<td><a href="URL?brand_id='. $row['brand_id']. '">'. $row['brand_id']. '</a></td>';

URL?brand_id=... 是包含品牌详细信息的页面的 URL,您将品牌 ID 传递到其中。

【讨论】:

  • Sergey Sergeyovich 你太棒了。非常感谢。
猜你喜欢
  • 2011-01-07
  • 2019-12-11
  • 1970-01-01
  • 2015-05-04
  • 1970-01-01
  • 2015-12-06
  • 1970-01-01
  • 1970-01-01
  • 2013-11-14
相关资源
最近更新 更多