Finker92 Posted January 4, 2012 Share Posted January 4, 2012 Hi all, I have written a piece of code querying the database to display the last ten posts from different users on a forum/blog. This is displaying the titles of the posts but I am unsure how to create a link (complete novice) to read the content of those posts. I get the syntax etc but can't really get my head around the target, if you catch my drift. I have created a new php file called recentposts but am unsure of how to take it from there. The code for both is below. The first piece of code works fine but when I click read more I am getting an undefined variable message on line 11 (I'm guessing there should be a link between the two pieces of code) and I am getting mysqli_fetch_array() expects parameter 1 to be mysqli_result on line 12. Any thoughts/hints/suggestions welcome. Thanks in advance. <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') //Make a connection to the database or die(mysqli_connect_error("Could not connect to the server")); //If it doesn't connect give the error message $latestposts= mysqli_query($connection,"SELECT author_id, title FROM blogposts ORDER BY timeofpost DESC LIMIT 9");//Query the database while($displayposts=@mysqli_fetch_array($latestposts)){ //go and get the information echo "{$displayposts['title']}</br>"; echo "<a href='recentposts.php'>Read more</a></br>"; } ?> And the recentposts.php is <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') or die(mysqli_connect_error("Could not connect to the server")); $detail= mysqli_query($connection,"SELECT * FROM blogposts WHERE 'title', 'content', 'timeofpost' = $content"); while($singlepage = mysqli_fetch_array($connection,$detail)){ extract($singlepage); echo "<h2>{$singlepage['title']}</h2></br>"; echo "{$singlepage['content']}</br>"; echo "{$singlepage['timeofpost']}"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254340-using-href/ Share on other sites More sharing options...
PhunkRabbit Posted January 4, 2012 Share Posted January 4, 2012 Depending on how the url's work for the blog posts it should be fairly simple to link to them dynamically. The PHP will just echo a static link with one or two dynamic components similar to: <?php echo '<a href="/blog/post/' . $blogpostid . '/">Read Blog Post</a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/254340-using-href/#findComment-1304137 Share on other sites More sharing options...
Finker92 Posted January 4, 2012 Author Share Posted January 4, 2012 OK, so now I am getting undefined index errors. I feel that I probably need to use $_GET somewhere here but I don't know where I am going wrong. From reading around it seems to me I should probably use isset somewhere? If this is very obvious please be patient... everybody starts somewhere. Any help or suggestions appreciated. <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') //Make a connection to the database or die(mysqli_connect_error("Could not connect to the server")); //If it doesn't connect give the error message $latestposts= mysqli_query($connection,"SELECT author_id, title FROM blogposts ORDER BY timeofpost DESC LIMIT 9");//Query the database while($displayposts=@mysqli_fetch_array($latestposts)){ //go and get the information echo "{$displayposts['title']}</br>"; echo "<a href='recentposts.php?id=content'>Read more</a></br>"; } ?> and then the other bit. It is running as far as the echo but I think I am missing something earlier? <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') or die(mysqli_connect_error("Could not connect to the server")); $content= mysqli_query($connection,"SELECT ('author_id''title''content') FROM blogposts ORDER BY timeofpost DESC LIMIT 9");; while($singlepage = mysqli_fetch_array($content)){ extract($singlepage); echo "<h3>{$singlepage['title']}</h3></br>"; echo "{$singlepage['content']}</br>"; echo "{$singlepage['timeofpost']}"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254340-using-href/#findComment-1304353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.