buffsteve24 Posted April 28, 2013 Share Posted April 28, 2013 Ok so basically I have created a simple blog for my website which does what I want it to do pretty much I'm having a problem with the date though If I echo the date out in to my page it just shows the main body of my content and not the actual date :/ the other problem is when I am echoing the blog into my page It is showing the same content two or three times instead of selecting the other content in the db I currently have two articles in my db but it will only show the article with the id of 1 instead of outputting id 1 and id 2 into there respective places on the page <?php$mysql = new mysqli('localhost', 'root', 'root', 'blog') or die('There was a problem connecting to the database');$stmt = $mysql->prepare('SELECT id, title, date, author, category, LEFT(body, 600) AS excerpt, body from posts ') or die('Problem preparing the query');$stmt->execute();$stmt->bind_result($id, $title, $body, $author, $category, $excerpt, $date);while($row = $stmt->fetch()) : $lastspaceindex = strrpos($excerpt, ' ');?> <?php endwhile; ?> then where I am echoing them out here my code is <div class="extra-wrap"><span class="text3"><a href="blog.php?id=<?php echo $id; ?>" class="link1"><?php echo $title; ?> </a></span><div class="inner4"><p> Posted by <b><?php echo $author; ?></b> in <b><?php echo $category; ?></b> </p></div></div><div class="clear"></div><div class="page2-box2"><figure class="page2-img1"><img src="images/page2-img2.jpg" alt=""></figure><div class="extra-wrap"><?php echo substr($excerpt, 0, $lastspaceindex) . "<a href='blog.php?id=$id'>...</a>"; ?><br><span class="text3"><?php echo substr() . "<a href='blog.php?id=$id'>Read More</a>"; ?></span></div> Quote Link to comment https://forums.phpfreaks.com/topic/277384-same-content-showing-please-help/ Share on other sites More sharing options...
cyberRobot Posted April 29, 2013 Share Posted April 29, 2013 (edited) For the date/body issue, have you tried switching the variables in the bind statement to match the column order in the prepare statement? <?php //... $stmt = $mysql->prepare('SELECT id, title, date, author, category, LEFT(body, 600) AS excerpt, body from posts ') or die('Problem preparing the query'); $stmt->execute(); $stmt->bind_result($id, $title, $body, $author, $category, $excerpt, $date); //... ?> Edited April 29, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/277384-same-content-showing-please-help/#findComment-1427104 Share on other sites More sharing options...
buffsteve24 Posted April 29, 2013 Author Share Posted April 29, 2013 For the date/body issue, have you tried switching the variables in the bind statement to match the column order in the prepare statement? <?php //... $stmt = $mysql->prepare('SELECT id, title, date, author, category, LEFT(body, 600) AS excerpt, body from posts ') or die('Problem preparing the query'); $stmt->execute(); $stmt->bind_result($id, $title, $body, $author, $category, $excerpt, $date); //... ?> Hi, Thanks that worked a charm amazing it's always the little things like that you miss Quote Link to comment https://forums.phpfreaks.com/topic/277384-same-content-showing-please-help/#findComment-1427146 Share on other sites More sharing options...
mac_gyver Posted April 29, 2013 Share Posted April 29, 2013 (edited) if you are still working on why only one (that last one) piece of information is being displayed, it's because your display code isn't inside of your while(){} loop. your display code is after the end of your while(){} loop and is only running once, after the while(){} loop has finished and it is using the last values fetched into the variables. Edited April 29, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/277384-same-content-showing-please-help/#findComment-1427170 Share on other sites More sharing options...
buffsteve24 Posted April 30, 2013 Author Share Posted April 30, 2013 if you are still working on why only one (that last one) piece of information is being displayed, it's because your display code isn't inside of your while(){} loop. your display code is after the end of your while(){} loop and is only running once, after the while(){} loop has finished and it is using the last values fetched into the variables. Thanks I will try that when I finish work and let you know if it solved it Quote Link to comment https://forums.phpfreaks.com/topic/277384-same-content-showing-please-help/#findComment-1427224 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.