0

Ok. I have ZERO PHP Knowledge, still good in editing php and all that stuff. Only know copy paste and have no knowledge what that means. Still would try to explain my problem.

I use variable to fetch data from mysql. Ex. my url is http://www.example.com/venue.php?vcity=New York.

Now, I want to replace New York with New-York. The real url I am trying to get is http://www.example.com/venue-new-york.php.

For that I added code in htaccess

RewriteRule ^venue-([^/]*)\.php$ /venue.php?vcity=$1 [L]

I Know what I added in htaccess is mostly perfect.

Now, I am using smarty so would be able to do lower case and replace space with dash. But that would not allow me to fetch data from mysql for some reason. In class file I have following code.

function getallvenueschedule()
	{
		global $db,$smarty;
		$sql = " SELECT * FROM table WHERE vcity = '$this->vcity' AND sch_date >= '$this->sch_date' ORDER BY timestmp ASC";
		$theList	= $db->getAll($sql); 
		return $theList;
	}

In the venue.php file below is code.

$vcity = $_GET['vcity'];
2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by phphit
1

Why not use the MySql REPLACE() command in your query:

SELECT *, REPLACE(vcity, ' ', '-') AS vcity_replaced FROM table WHERE vcity = '$this->vcity' AND sch_date >= '$this->sch_date' ORDER BY timestmp ASC

It might be possible to do in your htaccess, but that would require a regex that specifically targets each space, am not sure how that could be done, since you don't know how many there are going to be. You could match them, but am not sure how to replace them.

Edited by pritaeas: n/a

0

Why not use the MySql REPLACE() command in your query:

SELECT *, REPLACE(vcity, ' ', '-') AS vcity_replaced FROM table WHERE vcity = '$this->vcity' AND sch_date >= '$this->sch_date' ORDER BY timestmp ASC

It might be possible to do in your htaccess, but that would require a regex that specifically targets each space, am not sure how that could be done, since you don't know how many there are going to be. You could match them, but am not sure how to replace them.

Hi,

What should replace "vcity_replaced" as ?

Moreover, will I need to change venue.php file for that purpose.

0

I don't have more than two spaces in venue (usually only one space). So if htaccess works, i would accept it as of now, if no solution comes.

Edited by phphit: n/a

0

I think this would work for one space:

RewriteRule ^venue-([^/ ]*)( ?)([^/ ]*)\.php$ /venue.php?vcity=$1-$3 [L]

I am not sure yet how to fix it for more.

0

I am not sure yet how to fix it for more.

Ok. Any idea if same can work without htaccess. I am missing just something. (I have sent you PM also)

Edited by mike_2000_17: Fixed formatting

0

Solved in other way.

Actually no trick worked.

But what happen that url still work with "+" sign between two words (or say replace space with +).

I would not mind that "+" sign.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.