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
Designing a dynamic PHP page.
Moderator: General Moderators
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'];- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
make sure you have a valid value with something like:
post.php:
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
}(#10850)