Home  >  Article  >  Backend Development  >  关于PHP从数据库的关键词如何全部输出?

关于PHP从数据库的关键词如何全部输出?

WBOY
WBOYOriginal
2016-06-06 20:11:571083browse

====================================
数据库表是
id keywords
1 你好,很好,都好
1 都很好
1 很好,行

$str = $row['keywords'];
打印后是:
string(20) "你好,很好,都好"
string(26) "都很好"
string(34) "很好,行"

我想输入来的一些词,把他们分开加上链接。
以下代码是 phpwind框架,直接循环输出了。

$dosql->Execute("SELECT * FROM #@__infolist` WHERE (classid=1 ) ORDER BY id ASC LIMIT 0,100");

<code>{
    while ($row = $dosql->GetArray())
        echo  $str = $row['keywords'];  //这里 输出是  你好,很好,都好,都很好,很好,行
        $str_keywords= array_filter(explode(",",$str));  //目的是为了把逗号替换掉
}

foreach($str_keywords as $v){
    echo '<a href="#">'.$v.'</a>';   //结果这里只输出  <a href="#">很好 </a><a href="#">行 </a>
}`
</code>

为什么不全部输出呢? 只有<a href="#">很好 </a><a href="#">行 </a>
是用phpmywind框架。

回复内容:

====================================
数据库表是
id keywords
1 你好,很好,都好
1 都很好
1 很好,行

$str = $row['keywords'];
打印后是:
string(20) "你好,很好,都好"
string(26) "都很好"
string(34) "很好,行"

我想输入来的一些词,把他们分开加上链接。
以下代码是 phpwind框架,直接循环输出了。

$dosql->Execute("SELECT * FROM #@__infolist` WHERE (classid=1 ) ORDER BY id ASC LIMIT 0,100");

<code>{
    while ($row = $dosql->GetArray())
        echo  $str = $row['keywords'];  //这里 输出是  你好,很好,都好,都很好,很好,行
        $str_keywords= array_filter(explode(",",$str));  //目的是为了把逗号替换掉
}

foreach($str_keywords as $v){
    echo '<a href="#">'.$v.'</a>';   //结果这里只输出  <a href="#">很好 </a><a href="#">行 </a>
}`
</code>

为什么不全部输出呢? 只有<a href="#">很好 </a><a href="#">行 </a>
是用phpmywind框架。

<code>  $str_keywords 覆盖了之前的  $str_keywords值。。。
修改为 $str_keywords=  array_merge($str_keywords,  array_filter(explode(",",$str))); </code>

你把keywords 先组装成你想要的 字符串样式 在输出

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn