0

I am not looking for the code, but I am wondering how I would go about solving this issue. I have a simple site where a user submits form data that is stored on a database and then what they wrote is displayed on the mainpage each post in its own section. What would be need to make it is I can click on a post on the main page and be directed to a page displaying only that post so it would be like example.com/posts.php?id=$postId. What is the best way to go about this issue?

3 Answers 3

1

You can do it several ways. I would go with a simple link..

echo '<a href="example.com/posts.php?id="'.$postId.'">Link Name</a>';

5
  • But would that be creating a new page each time. I am looking to just click on the post and view it in another screen that seems to imply the linking page has been made already Aug 17, 2013 at 15:50
  • To open another window just add the HTML attribute "target='_blank'" Aug 17, 2013 at 15:51
  • 1
    No, it doesn't create a new page. It just opens the existing posts.php page. Aug 17, 2013 at 15:51
  • And then from there I would query the database to get the post? Aug 17, 2013 at 15:52
  • Correct, using the superglobal $_GET['id'] to grab the parameter from the URL Aug 17, 2013 at 15:53
0

That should accomplish what you want. Sending Id of a post via a GET method should be simple and safe. You can use that $_GET['id'] and display the post content as required

Also, in the posts.php ( or any other file ), when you detect a $_GET['id'], make sure you check the database if there's a post with that id. If there's not you could just display a gentle error message so that the user is not confused.

-1

Try this:

echo '<a href="URL.php?id=".$postId.">Link Name</a>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.