I'm having problems combining a str_replace with a foreach statement.
Here's the situation: I want to retrieve data from a mysql database, strip out the spaces in the data and replace them with underscores (to create a URL without spaces). Then I want to print out a list of the data (this will be used for site navigation.
Here's the code (omitting the database connection)
[code=php] <?php
$towns = mysql_query("SELECT DISTINCT Town FROM all3 WHERE County = 'SomeCounty' ORDER BY Town asc");
echo ("<b><span class=\"mystyle\">SomeCounty Locations</span></b><br>");
//Here's where the spaces are replaced by underscores
$mytowns = str_replace(" ", "_", $towns);
//Now the $mytown variables are looped
foreach ($mytowns as $mytown);
{
echo ("<a href=\"/hotels/CountyName/$mytown" . ".htm\" class=\"mystyle\">");
//Here I want to print the $towns names WITHOUT underscores. I know that what I have here can't be right, but I'm not sure how to get the values I want without the underscores.
echo ("$town");
echo ("</a><br>");
}
?>[/code]
Well, all I get is
parse error, unexpected ')' ... or
Invalid argument supplied for foreach() ...
It goes without saying that I'm new to this, and I'm obviously missing something basic :-)
Any help would be very gratefully received.