php - 动态地使用 href 链接映射表行
我有一个数组,用于动态创建表。 我有一个名称=值对 (Server=server.alias),正在提取其中的值,并希望将其超链接到另一个网页。
我需要帮助的是找出将别名与特定 href 链接映射的代码,我认为我必须对其进行硬编码。每个别名的 href 链接都不同,因此没有模式。
if 语句适合于此吗?还有其他建议可以做到这一点吗?谢谢。
预期输出:
Server
----------------
server1.alias <-- hreflink = http://server1.name.com:/9999
server2.alias <-- hreflink = http://server2.name.colo.com:/2999
到目前为止,我生成动态行的代码如下所示:
$keys = array('Server');
echo '<table><tr>';
foreach ($keys as $column)
echo '<th>' . $column . '</th>';
echo '</tr>';
foreach ($data as $row){
echo '<tr>';
foreach ($keys as $column)
if (isset($row[$column])){
echo '<td>' . $row[$column];
} else {
echo '<td>' . '' . '</td>';
}
}
echo '</table>';
I have an array which i use to dynamically create a table.
I have a name=value pair (Server=server.alias) which values are being extracted and would like to make it hyperlinked to another webpage.
What I need help is figuring out the code to map the alias name with a specific href link which I think I will have to hard code. The href link is different for each alias, so there is no pattern there.
Would an if statement be appropriate for this? Any other suggestions to do this? Thank you.
Expected Output:
Server
----------------
server1.alias <-- hreflink = http://server1.name.com:/9999
server2.alias <-- hreflink = http://server2.name.colo.com:/2999
My code so far generating the dynamic rows look like this:
$keys = array('Server');
echo '<table><tr>';
foreach ($keys as $column)
echo '<th>' . $column . '</th>';
echo '</tr>';
foreach ($data as $row){
echo '<tr>';
foreach ($keys as $column)
if (isset($row[$column])){
echo '<td>' . $row[$column];
} else {
echo '<td>' . '' . '</td>';
}
}
echo '</table>';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为解决您问题的关键是您需要更多信息才能使用 foreach 创建您想要的列表。我的建议是使用这样的东西:
你肯定需要数组中的所有信息,否则,你将永远无法做你想做的事。
编辑:
对于上面的数组,foreach 循环将如下所示:
缺少格式化代码,但您明白了。
I think that the key to solving your problem is that you will need more information to be able to create the list that you want with a foreach. My suggestion would be to use something like this :
You definitely need all info in your array, otherwise, you'll never be able to do what you want.
EDIT:
With the above array, the foreach loop would be like this :
The formatting code is missing, but you get the idea.