0

The flowing code outputs this result from my database

<?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";
}
    ?>

the out put from table looks like this

hypergrid.org:8002/;Isolde Caron with origional data looking like '0012f478-60fe-49bf-bb2d-48a889191afd;http://hypergrid.org:8002/;Isolde Caron'

I wish to replace the ";" in the result with spaces...

any ideas would be greatly appreciated tia john

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • 1
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). You will also want to [Prevent SQL Injection!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Nov 17 '14 at 16:42

2 Answers2

2

Just simple replace the character:

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

NOTES:

  • THe foreach is unnecesarry in your while loop, since row is a single row.

  • Use mysqli or PDO instead of mysql functions, because mysql functions are deprecated.

vaso123
  • 12,347
  • 4
  • 34
  • 64
0

Use str-replace()

echo "<td><center>" . str_replace(';', ' ', $cell) . "</td>";
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119