跨表格单元格的超链接?

发布于 2025-01-04 06:52:04 字数 952 浏览 0 评论 0原文

我正在尝试从拆分为表行中两个单元格的两段文本创建超链接。

我正在使用 PHP 生成表,以将数据库中的结果回显到表中。 当它回显时,它会在末尾生成一个带有 GET 变量的超链接,允许用户访问与该信息相关的页面。

问题是我似乎无法生成跨越这些表格单元格的超链接,我浏览了网络,没有任何内容表明我不能这样做。

正如您从下面的屏幕截图中看到的,我在一个表格单元格内生成一个超链接,但我希望另一个表格单元格具有相同的超链接。

在此处输入图像描述

代码

while ($row = $db->fetch_assoc($newest))
                        {
                            echo "<tr>";
                                echo "<td>";
                                    echo  "<a href='manager.php?method=view&id=".$row['id']."'>".$row['first_name']." ". $row['second_name']. "</td><td>".$row['company_name']."</a>";
                                echo "</td>";
                            echo "</tr>";
                        }

我感觉我只需要生成两个单独的超链接对于表格单元格。

不过,我希望这里有人能证明我错了,并为我节省了几行代码。

谢谢 :)

I am trying to create a hyperlink from two pieces of text split over two cells in a table row.

I am generating my table using PHP to echo out the results from my database to a table.
When it echo's it generates a hyperlink with GET variables at the end which allow the user to visit a page relevant to that information.

The problem is that I can't seem to generate a hyperlink that will go across those table cells, I have looked around the web and there is nothing that says I cannot do this.

As you can see from the screenshot below I am generating a hyperlink inside one table cell but I want the other table cell to have the same hyperlink.

enter image description here

Code

while ($row = $db->fetch_assoc($newest))
                        {
                            echo "<tr>";
                                echo "<td>";
                                    echo  "<a href='manager.php?method=view&id=".$row['id']."'>".$row['first_name']." ". $row['second_name']. "</td><td>".$row['company_name']."</a>";
                                echo "</td>";
                            echo "</tr>";
                        }

I have a feeling that I will just have to generate two separate hyperlinks for the table cells.

However I am hoping someone here can prove me wrong and save me a few lines of code.

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

紫轩蝶泪 2025-01-11 06:52:04

使用本机超链接,您必须为每个单元格创建单独的包装器。

但是,如果您想使用 JS 进行链接和重定向,您可以执行以下操作:

.....
<tr class="clickable" data-href="http://google.com">
<td>cell-1</td>
<td>cell-2</td>
<td>cell-3</td>
</tr>
....

然后:

$(function(){
    $('tr.clickable').click(function(){
        window.location.href = $(this).attr('data-href');
    });
});

Using native hyperlinks, you will have to create separate wrappers for each cell.

However, if you want to use JS for linking and redirecting, you could do something like:

.....
<tr class="clickable" data-href="http://google.com">
<td>cell-1</td>
<td>cell-2</td>
<td>cell-3</td>
</tr>
....

and then:

$(function(){
    $('tr.clickable').click(function(){
        window.location.href = $(this).attr('data-href');
    });
});
別甾虛僞 2025-01-11 06:52:04

只需用 JS 解决它:

echo "<tr onclick=\"location.href='manager.php?method=view&id=".$info.";'\">";

Simply work around it with JS:

echo "<tr onclick=\"location.href='manager.php?method=view&id=".$info.";'\">";
牵你手 2025-01-11 06:52:04

如果您不想破坏表结构(即将名称和公司放入一个(多列)单元格中),恕我直言,除了生成两个超链接之外别无选择。

您可能想要做的是使用一些 CSS 来实现悬停效果,并使用一些 JavaScript 来注册用户单击的单元格(根据上面的结构,您可以将其与 tr 元素关联)。

If you do not want to break the table structure (ie. putting the name and the company into one (multi-column) cell), there is IMHO no way other than generating two hyperlinks.

What you might want to do is to use some CSS for a hover effect and some JavaScript to register a user clicked on a cell (which you can, given the structure above, associate with the tr element).

友欢 2025-01-11 06:52:04

你不能这样做。尝试改为:

 while ($row = $db->fetch_assoc($newest))
    {
        $url = "manager.php?method=view&id=".$row['id'];
        echo "<tr>";
            echo "<td><a href=\"" . $url.  "\">" . $row['first_name']." ". $row['second_name']. "</a></td>";
            echo "<td><a href=\"" . $url.  "\">" . $row['company_name'] . "</a></td>";
        echo "</tr>";
    }

You can not do it like this. Try instead:

 while ($row = $db->fetch_assoc($newest))
    {
        $url = "manager.php?method=view&id=".$row['id'];
        echo "<tr>";
            echo "<td><a href=\"" . $url.  "\">" . $row['first_name']." ". $row['second_name']. "</a></td>";
            echo "<td><a href=\"" . $url.  "\">" . $row['company_name'] . "</a></td>";
        echo "</tr>";
    }
提赋 2025-01-11 06:52:04
while ($row = $db->fetch_assoc($newest))
{
    echo "<tr>";
    echo "<td>";
    echo "<a href='manager.php?method=view&id=".$row['id']."'>".$row['first_name']." ". $row['second_name']."</a></td><a href='manager.php?method=view&id=".$row['id']."'>".$row['company_name']."</a><td></td>";
    echo "</td>";
    echo "</tr>";
}
while ($row = $db->fetch_assoc($newest))
{
    echo "<tr>";
    echo "<td>";
    echo "<a href='manager.php?method=view&id=".$row['id']."'>".$row['first_name']." ". $row['second_name']."</a></td><a href='manager.php?method=view&id=".$row['id']."'>".$row['company_name']."</a><td></td>";
    echo "</td>";
    echo "</tr>";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文