Page 1 of 1

retreving info from a db ...

Posted: Sat Nov 29, 2008 8:10 pm
by eggy
Here is what i am trying to accomplish, am not looking for any code .. just guide in right direction ...

Website i am working on will have multiple users that will have their own directory such as this:

Code: Select all

 
http://www.somedomain.com/jsmith/
 
Information that will pertain to J. Smith will be retrieved from the db. will be displayed on the page when it is open.

I can do this 2 ways. I can embed jsmith id on the page and pull information from the database and that would be it.

I would like to use sub directory as a pointer of sorts that would pull information from the database.

Is that possible?

could i use it in following fashion ...

Code: Select all

SELECT * FROM table WHERE id=jsmith
Any ideas and pointers would be greatly appreciated :)

Thank you

Greg

Re: retreving info from a db ...

Posted: Sat Nov 29, 2008 11:31 pm
by requinix
It's called URL rewriting. Basically, you tell the server that requests for some kind of URL get "rewritten" into something else. Best part is the user won't know about it: they still see the original address.
For example, a request for /(letters) that doesn't exist can be rewritten to /user.php?id=(letters). Then your PHP script can handle it however you want.

Apache needs the mod_rewrite module. Once that's installed you can put a bit in your site's .htaccess file like

Code: Select all

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /(\w+) /user.php?id=$1 [L,NC,QSA]
If you want something more complicated than just displaying one page you'll (probably) need a more complicated RewriteRule.