Page 1 of 1

Designing a dynamic PHP page.

Posted: Fri Jun 02, 2006 5:04 pm
by kelt686
I am working on designing a web forum and I have a sever case of Coder's Block. I have accessed a MYSQL database where my information is stored and loaded titles, authors, and datestamps into a table. What I would like to do is to allow the click on the title of any post to view that post and its replies. Technically I wanted to do this by linking the title of the post to post.php and somehow passing the $postID variable from the forum.php page to post.php and then re-querying the database using the "SELECT * WHERE postID = $postID" line. I thought about using hidden forms in HTML and the onClick feature in javaScript, but I could not figure out how to then pass the $postID variable to the post.php page. Any help would be greatly appreciated. Thanks,

Patrick

Posted: Fri Jun 02, 2006 5:08 pm
by PrObLeM

Code: Select all

echo "<a href='post.php?p=" . $postID . "'>" . $Title . "</a>";

to get the variable in post.php you will use $_GET['p'];

post.php:

Code: Select all

//SELECT * WHERE postID = $_GET['p']
echo "you want to look at post: " .  $_GET['p'];

Posted: Fri Jun 02, 2006 5:17 pm
by Christopher
make sure you have a valid value with something like:

post.php:

Code: Select all

$postID = (int) $_GET['p'];    // for integer keys
$postID = preg_replace('/[^a-zA-Z0-9\-]/', '', $_GET['p']);    // or for alphanum keys
if ($postID) {
    //SELECT * WHERE postID = $postID
    echo "you want to look at post: $postID";
} else {
    // error
}

Posted: Mon Jun 05, 2006 8:25 am
by kelt686
Thanks a lot guys. This really helped me out.