Click to See Complete Forum and Search --> : $_get


myonosken
10-26-2006, 02:32 PM
Hey all, thanks for looking.

Anyway, I'm using a GET function (id=X) in my page, and I was wondering how I could use this value (stored in $id) in SQL? For example:

$sql = "SELECT * FROM `forum1thread` WHERE `forumid`='58' ORDER BY `dateline` DESC";

The forum id bit, I would like to be equal to the appended section of the URL.

I am also quite interested in finding out how if it is possible to use this same variable in an URL. Eg: www.zzz.com/"$id".jpg

Edit: Whoops. Where are my manners. Thanks for helping.

Sheldon
10-26-2006, 02:35 PM
something like...
$sql = "SELECT * FROM `forum1thread` WHERE `forumid`='".$_GET['forumid'] ."' ORDER BY `dateline` DESC";

but you may want to run security checks on the get data before using it.

so_is_this
10-26-2006, 02:36 PM
Something like this?
$id = '';
if (isset($_GET['id']) && !empty($_GET['id'])) $id = addslashes($_GET['id']);

...etc...

$sql = "SELECT * FROM `forum1thread` WHERE `forumid`= '{$id}' ORDER BY `dateline` DESC";

myonosken
10-26-2006, 02:39 PM
Thanks a lot. That should work. And would the URLs be possible as well?

so_is_this
10-26-2006, 02:40 PM
...continuing where I left off before...
<a href="somepage.php?id=<?=$id?>">some text</a>

myonosken
10-26-2006, 02:45 PM
Thanks I'll go try that.

As for the SQL, it worked perfect. Thanks.

so_is_this
10-26-2006, 04:48 PM
Salud! ;)