I’m building a blog for a website and I’m learning PDO as I go. I need some help with some URL and PDO stuff.
Currently I can display my blog entries and all associated info on the blog page. When I click on the title (linked to the full blog post) I am doing this:
<h2><a href="blog.php?<?php echo urlencode($row['title'])?>"><?php echo $row['title'] ?></a></h2>
The output gives me something like this:
http://www.mysite.com/blog.php?my+blog+post+title+
So, I figured I’d use $_GET to see if $row['title'] is set. If so, display the full blog post else display all blog entries like so:
<?php
if ($_GET == urlencode($sth->fetch())) { ?> **//This is where I'm stuck**
... Code here to display full blog post
<?php } else { ?>
<?php
while($row = $sth->fetch()) { ?>
.... Code here to display ALL blog posts
So, how do I use $_GET to check if the title matches and if so, display the full post? If this isn’t the most efficient way, please recommend an alternative. Thanks!!
The most efficient way would be to do it like Stack Overflow; look:
They have both the post ID and the title, but they only use the ID to fetch the right data.