Mysql with URL keyword

SimpleJ
SimpleJ used Ask the Experts™
on
Hello.

I have a "home made" php-mysql website available through http://mydomain.com.

I want to achieve the following:

Let`s say I enter the url : http://mydomain.com/something 
I would like to read this url, get the part of a url called "something" and lookup this word("something") in mysql database.

I`ve created a new folder called "something" containing index.php which reads url, gets the part of url "something" and querys a select.

But this is not a good solution when there are a lot of words in a database. Does anyone have a solution how to achieve the same, without having to create a directory for each word in database?

thx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I think you want to look into mod_rewrite (assuming you are running on apache) and configure it so that the "something" part of your URL is pulled off as a parameter and you can use that in your query.  You would have all of your code in your index.php in your root directory.  This index.php file would be what runs your query using "something" as part of your where clause.

Here's a link to a sample tutorial that may be of help: http://www.workingwith.me.uk/articles/scripting/mod_rewrite
Set up mod_rewrite like so

In Apache / .htaccess

RewriteEngine On
RewriteRule ^(.*)$ /index.php?word=$1 [L]

Then in index.php in your website's root directory you can pick up the rewritten data like so

<?php

.....

$word = mysql_real_escape_string( $_GET['word'] );
$rs = mysql_query("SELECT * FROM myTable WHERE word = '$word' ");

Author

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial