RCT3Xtreme Posted May 7, 2007 Share Posted May 7, 2007 Hi everyone, I am currently making a website, with a blog. I have a database set up and all php is working fine - no errors etc... but: (website link: http://creative.design-uk.biz/blog.php/) When I display the content of each entry, the content doesn't actually show... it appears as one '<'. And the comments - well there's no trace of them.. Here is the PHP code: [pre] //my sql connect is here // If ID is set then - if (isset($_GET["id"])) { // Display one entry with the ID of GET, and it's comments. // Function for one entry. function constructentry($entry) { $entry = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . stripslashes($entry["title"]) . '</a><br /><span class="date"> - ' . $entry["insert_date"] . '</span></h2>'; $entry = $entry . '<div class="spacer"></div>'; $entry = $entry . '<div class="blogentry">' . stripslashes($entry["content"]) . '</div>'; $entry = $entry . '<h3>Comments</h3>' . stripslashes(buildcomments($entry["entry_id"])); return $entry; } // Function for the entry's commments. function buildcomments($entryId) { $commenthtml = ''; return $commenthtml; } // SQL For the entry. $entrysql = " select entry_id, title, content, date_format(insert_date,'%a %D %M, %y at %h o\'clock (%p)') as insert_date from Entry where entry_id= " . $_GET['id'] . ";"; $entries = mysql_query($entrysql) or die("Error accessing database: " . mysql_error()); // SQL for comments. $commentsql = " select entry_id, comment_id, author, content, date_format(insert_date, '%a %D %M, %y at %HH') as insert_date from Comment where approved= 1 and entry_id= " . $_GET['id'] . ";"; $comments = mysql_query($commentsql) or die("Error accessing database: " . mysql_error()); $bloghtml = ""; if (mysql_num_rows($entries) > 0) { while ($entry = mysql_fetch_assoc($entries)) { $bloghtml = $bloghtml . constructentry($entry); } } $toplinks = ''; $bottomlinks = '<p style="text-align: center;"><a href="blog.php">All Entries</a> - <a href="#wrapper">Back to top</a></p>'; } else { // If ID Isn't set then - // Display all entry titles and dates. // Function for all entries. function constructentries($entry) { $entry = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . $entry["title"] . '</a><br /><span class="date"> - ' . $entry["insert_date"] . '</span></h2>'; $entry = $entry . '<div class="spacer"></div>'; return $entry; } // Do all entries $entrysql = " select entry_id, title, date_format(insert_date,'%a %D %M, %y at %h o\'clock (%p)') as insert_date from Entry order by entry_id desc;"; $entries = mysql_query($entrysql) or die("Error accessing database: " . mysql_error()); $bloghtml = ""; if (mysql_num_rows($entries) > 0) { while ($entry = mysql_fetch_assoc($entries)) { $bloghtml = $bloghtml . constructentries($entry); } } $toplinks = 'All Entries'; $bottomlinks = '<p style="text-align: center;"><a href="#wrapper">Back to top</a></p>'; } // mysql quit is here. [/pre] Please help... I'm extremely confused! Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/ Share on other sites More sharing options...
Lumio Posted May 7, 2007 Share Posted May 7, 2007 I didn't read all of you code... but: <?php //code ... function constructentry($entry) { $entry = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . stripslashes($entry["title"]) . '[/url] <span class="date"> - ' . $entry["insert_date"] . '</span></h2>'; $entry = $entry . '<div class="spacer"></div>'; $entry = $entry . '<div class="blogentry">' . stripslashes($entry["content"]) . '</div>'; $entry = $entry . '<h3>Comments</h3>' . stripslashes(buildcomments($entry["entry_id"])); return $entry; } //code ?> You get $entry as an Array. That's ok. Then you redefine it as a string containing '<h2>...</h2>'; So... what do you think is now in $entry? Is it an array? Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/#findComment-247202 Share on other sites More sharing options...
RCT3Xtreme Posted May 7, 2007 Author Share Posted May 7, 2007 Yeah, think so... but the main problem is that the PHP will not get content of entry or comments from the MySQL database. Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/#findComment-247209 Share on other sites More sharing options...
trq Posted May 7, 2007 Share Posted May 7, 2007 but the main problem is that the PHP will not get content of entry or comments from the MySQL database. No. The main problem has been described above. Fix that problem and if you still have issues, post the relevent new code. And please, use the [ code ] [/ code ] (without the spaces) tags for syntax highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/#findComment-247217 Share on other sites More sharing options...
RCT3Xtreme Posted May 7, 2007 Author Share Posted May 7, 2007 Sorry, ignore me.. I'm new to PHP. So I change it to: $entry = $entry . '<h2....'; etc. If I am wrong, then please correct me. (actually, just trying to work out now) Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/#findComment-247226 Share on other sites More sharing options...
trq Posted May 7, 2007 Share Posted May 7, 2007 You can't overright your $entry variable as it holds your result. Try something like.... <?php //code ... function constructentry($entry) { $return = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . stripslashes($entry["title"]) . '</a> <span class="date"> - ' . $entry["insert_date"] . '</span></h2>'; $return .= . '<div class="spacer"></div>'; $return .= . '<div class="blogentry">' . stripslashes($entry["content"]) . '</div>'; $return .= . '<h3>Comments</h3>' . stripslashes(buildcomments($entry["entry_id"])); return $return; } //code ?> Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/#findComment-247230 Share on other sites More sharing options...
RCT3Xtreme Posted May 7, 2007 Author Share Posted May 7, 2007 Yeah I just figured that one out. Now to get the comments working... >.< Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/#findComment-247233 Share on other sites More sharing options...
RCT3Xtreme Posted May 7, 2007 Author Share Posted May 7, 2007 Yes! It's working. Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/#findComment-247263 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.