Quick question. please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mkb116
Forum Newbie
Posts: 1
Joined: Thu Jul 31, 2008 9:10 pm

Quick question. please help

Post by mkb116 »

I am dieing trying to figure this out for days! Searching is not helping. How do I use str_replace with an array. I have a list of results. I need the str_replace to go through each result as it is printed and change all the spaces with "+" symbols so they can be transfered through the url bar.

Here is what my code.


<?php
include("dbinfo.inc.php");
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT model, COUNT(model) FROM table1 GROUP BY model";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
echo "<a href=search.php?var2=". $row['$model'] .">". $row['model'] ."</a> (". $row['COUNT(model)'] .")";
echo "<br>";
}
?>


Please help!
SomeoneE1se
Forum Newbie
Posts: 20
Joined: Sat May 31, 2008 2:53 am

Re: Quick question. please help

Post by SomeoneE1se »

and

Code: Select all

 
<?php
include("dbinfo.inc.php");
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
 
$query = "SELECT model, COUNT(model) FROM table1 GROUP BY model"; 
 
$result = mysql_query($query) or die(mysql_error());
 
while($row = mysql_fetch_array($result)){
    echo "<a href=search.php?var2=". str_replace(' ', '+', $row['$model']) .">". $row['model'] ."</a> (". $row['COUNT(model)'] .")";
    echo "<br>";
}
?>
 
dosen't work?
Post Reply