gpt4 book ai didi

php - 将标签添加到数据库值

转载 作者:行者123 更新时间:2023-11-29 02:58:16 25 4
gpt4 key购买 nike

我从数据库中获取一些值,我想拆分它并向其中添加 html 标签。

$sql = "SELECT
ip_adres,
GROUP_CONCAT(DISTINCT nickname2 ORDER BY nickname2) nickname
FROM
users
GROUP BY ip_adres
HAVING COUNT(*) > 1";
$users = $db->prepare($sql);
$users->execute();

foreach($users as $u){
$nick = $u['nickname'];
$ip = $u['ip_adres'];
echo "$nick $ip";
}

$nick输出类似于 value1,value2现在我想给这两个值都添加一个 a href所以输出必须像 <a href=test.php?url=value>value1</a>, <a href=test.php?url=value2>value2</a>所以每个昵称都可以点击并 href 到昵称页面我该怎么做?

最佳答案

尝试

<?php

if($s = $db->query('SELECT
ip_adres,
GROUP_CONCAT(DISTINCT nickname2 ORDER BY nickname2) namen
FROM
users
GROUP BY ip_adres
HAVING COUNT(*) > 1')) {
while ($row = $s->fetch(PDO::FETCH_ASSOC)) {
$c = '';
$nicks = explode(',', $row['namen']);
foreach($nicks as $nick) {
echo "
$c <a href=$nick>$nick</a>
";
$c = ', ';
}
echo ' IP-Adres (' . $row['ip_adres'] . ')<br>';
}
}

?>

关于php - 将标签添加到数据库值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27676191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com