Designing a dynamic PHP page.

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
kelt686
Forum Newbie
Posts: 2
Joined: Fri Jun 02, 2006 4:47 pm

Designing a dynamic PHP page.

Post 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
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post 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'];
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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
}
(#10850)
kelt686
Forum Newbie
Posts: 2
Joined: Fri Jun 02, 2006 4:47 pm

Post by kelt686 »

Thanks a lot guys. This really helped me out.
Post Reply