php - 更改查询的输出

标签 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 with origional data looking like '0012f478-60fe-49bf-bb2d-48a889191afd;http://hypergrid.org:8002/;Isolde Caron'

我想替换“;”结果中有空格...

任何想法将不胜感激 蒂亚 约翰

最佳答案

只是简单的替换字符:

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

注意事项:

  • foreach 在您的 while 循环中是不必要的,因为 row 是单行。

  • 使用 mysqli 或 PDO 而不是 mysql 函数,因为 mysql 函数已被弃用。

关于php - 更改查询的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26977481/

相关文章:

php - 带有准备语句的多个 AVG

php - 重定向 - 替代 "&lt;meta http-equiv=' 刷新'/>”?

Mysql 密码哈希被保存到 mysql.user 表中的插件列中

php - 如何使用 PhpSpreadsheet 从表格单元格中检索日期?

php - 如果数据为空,如何在查询中使用计数来计算 0

mysql - SQL 连接 : group with order

php - php中mysql中两个日期之间的总和

mysql - 如何将django项目(考勤系统)上传到centOS服务器

javascript - 是否可以在 Ajax 语句中使用字符串来引用 json 对象?

phpoffice/phpspreadsheet - 如何从 getHighestRow() 中排除没有值的单元格