Page 1 of 1

PHP and MySQL one page to show all

Posted: Wed Apr 15, 2009 2:35 pm
by tomsace
Hey,
I was wondering how to use php to show mysql data on a webpage, but use the same webpage to show different results.Kind of like webpage.php?id=something so I can just change the id in the url to view different mysql content if thats possible??

If not how would I go about doing something else similar to this?

Thanks alot.

Re: PHP and MySQL one page to show all

Posted: Wed Apr 15, 2009 3:22 pm
by andyhoneycutt
Well, the id will be present in the $_GET global, so assuming it's url.php?id=1234, you could use the $_GET['id'] variable to modify your sql statement. Be sure to sanitize any data you use in this way before passing it on to mysql. Functions such as mysql_real_escape_string are recommended, as well as variable typecasting where you can. I like to use an sprintf() statement to build my sql statement anymore, or rely on a package like PDO.

-Andy

Re: PHP and MySQL one page to show all

Posted: Thu Apr 16, 2009 11:08 am
by tomsace
Hey,
Thanks alot for the help, I am having trouble finding any pages on the web to help me do this, it sounds like you do this kind of stuff alot so just wondering if you knew any websites with good demos and tutorials on this?
Its my first time doing anything at all like this so all sounds a bit confusing lol