更改查询输出

时间:2014-11-17 16:41:44

标签: php mysql

流动代码从我的数据库输出此结果

<?php
$result = mysql_query("SELECT SUBSTRING(UserID,45) FROM GridUser where Online ='True' "     );
if (!$result) {
die("query error");
}
$fields_num = mysql_num_fields($result);
echo "<table border='0'><tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr>";
foreach($row as $cell)
    echo "<td><center>$cell</td>";
echo "</tr>\n";
}
    ?>

表中的输出看起来像这样

  

hypergrid.org:8002 /; Isolde Caron    原始数据看起来像   &#39; 0012f478-60fe-49bf-bb2d-48a889191afd; http://hypergrid.org:8002/;Isolde Caron&#39;

我希望更换&#34;;&#34;在结果中有空格......

任何想法都将不胜感激 TIA 约翰

2 个答案:

答案 0 :(得分:2)

只需简单地替换角色:

echo "<td><center>" . str_replace(';', ' ', $cell) . "</td>";

注意:

  • while循环中,foreach是不必要的,因为行是一行。

  • 使用mysqli或PDO代替mysql函数,因为不推荐使用mysql函数。

答案 1 :(得分:1)

使用str-replace()

echo "<td><center>" . str_replace(';', ' ', $cell) . "</td>";