跨表格单元格的超链接?
我正在尝试从拆分为表行中两个单元格的两段文本创建超链接。
我正在使用 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用本机超链接,您必须为每个单元格创建单独的包装器。
但是,如果您想使用 JS 进行链接和重定向,您可以执行以下操作:
然后:
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:
and then:
只需用 JS 解决它:
Simply work around it with JS:
如果您不想破坏表结构(即将名称和公司放入一个(多列)单元格中),恕我直言,除了生成两个超链接之外别无选择。
您可能想要做的是使用一些 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).你不能这样做。尝试改为:
You can not do it like this. Try instead: