retreving info from a db ...

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
eggy
Forum Newbie
Posts: 1
Joined: Sat Nov 29, 2008 7:57 pm

retreving info from a db ...

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: retreving info from a db ...

Post 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.
Post Reply