我有一个名为 links 的字段,它接受以逗号分隔的 URL 列表,例如“www.bbc.co.uk, www.itv.co.uk”
然后,当我输出该字段的内容时,我将其包装在如下代码中:
<li><a href='http://<?php echo htmlout($name['links']); ?>'><?php echo htmlout($name['links']); ?></a></li>
当添加单个链接时,这可以正常工作,但是当添加多个链接时,就会导致问题。
例如,如果我有两个链接,一个是 www.bbc.co.uk,一个是 www.itv.co.uk,然后我将鼠标悬停在链接上(它是一个链接而不是两个),它显示为:
http://www.ts.co.uk%2C%20www.bbc.co.uk/
现在我在想,因为它们是用逗号分隔的,所以可能有某种方法可以将其用作挂钩来拆分 URL,但我不确定这是否可能。
任何帮助表示赞赏。谢谢
在下面编辑
在下面添加了一些代码,因为我已经有一个数组。我可以在数组中有一个数组吗?我应该在这种情况下吗?我应该把建议的代码放在哪里?
INDEX.PHP(控制器)
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
try
{
$sql = "SELECT player.id, player.name AS name, age, position, height, weight, GROUP_CONCAT(distinct previousclubs.name) previousclubs,
satscore, gpa, GROUP_CONCAT(distinct link) link, email
FROM player INNER JOIN playerpreviousclubs
ON player.id = playerid
INNER JOIN previousclubs
ON previousclubid = previousclubs.id
INNER JOIN links
ON links.playerid = player.id
WHERE email = '$username'";
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching details: ' . $e->getMessage();
include 'error.html.php';
exit();
}
foreach ($result as $row)
{
$names[] = array(
'id' => $row['id'],
'name' => $row['name'],
'age' => $row['age'],
'position' => $row['position'],
'height' => $row['height'],
'weight' => $row['weight'],
'previousclubs' => $row['previousclubs'],
'satscore' => $row['satscore'],
'gpa' => $row['gpa'],
'links' => $row['link'],
'email' => $row['email']
);
}
include 'profiles.html.php';
我的模板目前看起来像这样:
配置文件.HTML.PHP
<p>Welcome <?php echo $row['name'] ?> . Below are your profile details:</p>
<?php foreach ($names as $name): ?>
<form action="" method="post">
<ol>
<li class="listleft">Name:</li>
<li><?php echo htmlout($name['name']); ?></li>
<li class="listleft">Age:</li>
<li><?php echo htmlout($name['age']); ?></li>
<li class="listleft">Position:</li>
<li><?php echo htmlout($name['position']); ?></li>
<li class="listleft">Height:</li>
<li><?php echo htmlout($name['height']); ?></li>
<li class="listleft">Weight:</li>
<li><?php echo htmlout($name['weight']); ?></li>
<li class="listleft">Previous Clubs:</li>
<li><?php echo htmlout($name['previousclubs']); ?></li>
<li class="listleft">GPA:</li>
<li><?php echo htmlout($name['satscore']); ?></li>
<li class="listleft">SAT Score:</li>
<li><?php echo htmlout($name['gpa']); ?></li>
<li class="listleft">Links:</li>
<li><a href='http://<?php echo htmlout($name['links']); ?>'><?php echo htmlout($name['links']); ?></a></li>
</ol>
</form>
<?php endforeach; ?>