Noskiw Posted November 5, 2009 Share Posted November 5, 2009 <?php $title = "Blog"; $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); function bbcode($string) { if ($string) { $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]', ' ', '', ''); $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>', '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">', '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />'); $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string); return $new_string_2; } } //start pagination $query = "SELECT * FROM blog ORDER BY id DESC"; include ('pagination2.php'); $paginator = new pagination($_GET['page'], $query); $paginator->results_per_page = 2; $paginator->padding(2); $paginator->link_prefix = 'http://localhost/dynamic web page/index.php?p=blog&page='; $paginator->link_suffix = ''; $paginator->page_nums_separator = ' | '; $paginator->paginate(); echo "<h1>Blog</h1>\n"; $query = mysql_query("SELECT * FROM blog ORDER BY id DESC"); if (mysql_num_rows($query) == 0) { echo "<hr />There are no posts yet, make the first in the admin section!\n"; } echo "<h2>Newest Post!</h2>"; while ($row = mysql_fetch_assoc($paginator->resource())) { echo "<hr />"; $id2 = $row['id']; $title2 = $row['title']; $name = $row['name']; $email = $row['email']; $post = $row['post']; $date = $row['date']; $time = $row['time']; echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(substr($post,0,201), wordwrap($post, 118, "<br />", true)))); if(strlen($post) > 201){ echo "...<a href='./index.php?p=blog&p=post&id=" . $id2 . "'>Read More</a><hr /><h3>Comments</h3>"; $query2 = mysql_query("SELECT * FROM comments ORDER BY id DESC"); while($row2 = mysql_fetch_assoc($query2)){ $id3 = $row['id']; $name2 = $row['name']; $email2 = $row['email']; $comm = $row['comment']; $date2 = $row['date']; $time2 = $row['time']; echo "<table width='60%'><tr><td><b>Posted by: " . $name2 . "(" . $email2 . ") at " . $time2 . " on " . $date2 . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(wordwrap($comm, 118, "<br />", true)))); } echo "</td></tr></table>\n"; }else{ echo "<hr /><h3>Comments</h3></td></tr></table>\n"; } } echo $paginator; echo "<hr />\n"; echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>\n"; ?>[/code] I want to be able to create a comments section on my blog, but I get this error... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\dynamic web page\inc\blog.php on line 69 Please could someone help me? Quote Link to comment https://forums.phpfreaks.com/topic/180450-comments-section-on-blog/ Share on other sites More sharing options...
mikesta707 Posted November 5, 2009 Share Posted November 5, 2009 that usually means your query has failed. Echo the mysql_error() and post it Quote Link to comment https://forums.phpfreaks.com/topic/180450-comments-section-on-blog/#findComment-951964 Share on other sites More sharing options...
Noskiw Posted November 5, 2009 Author Share Posted November 5, 2009 Nevermind that. I solved that now. But I'm having a huge problem sorting the comments page out. I've made it so that you can post it to the db... But my problem is, is that I can't select the post I want it to go to. There are no errors, but you might want to see my code and tell me what's wrong with it. <?php $title = "Blog"; $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); function bbcode($string) { if ($string) { $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]', ' ', '', ''); $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>', '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">', '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />'); $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string); return $new_string_2; } } //start pagination $query = "SELECT * FROM blog ORDER BY id DESC"; include ('pagination2.php'); $paginator = new pagination($_GET['page'], $query); $paginator->results_per_page = 2; $paginator->padding(2); $paginator->link_prefix = 'http://localhost/dynamic web page/index.php?p=blog&page='; $paginator->link_suffix = ''; $paginator->page_nums_separator = ' | '; $paginator->paginate(); echo "<h1>Blog</h1>\n"; $query = mysql_query("SELECT * FROM blog ORDER BY id DESC"); if (mysql_num_rows($query) == 0) { echo "<hr />There are no posts yet, make the first in the admin section!\n"; } echo "<h2>Newest Post!</h2>"; while ($row = mysql_fetch_assoc($paginator->resource())) { echo "<hr />"; $id2 = $row['id']; $title2 = $row['title']; $name = $row['name']; $email = $row['email']; $post = $row['post']; $date = $row['date']; $time = $row['time']; echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(substr($post,0,201), wordwrap($post, 118, "<br />", true)))); if(strlen($post) > 201){ echo "...<a href='./index.php?p=blog&p=post&id=" . $id2 . "'>Read More</a><hr /><h3>Comments</h3>\n"; }else{ echo "<hr /><h3>Comments</h3>\n"; } $query2 = mysql_query("SELECT * FROM comments WHERE pid='" . $id2 . "'ORDER BY id DESC"); $row99 = mysql_fetch_assoc($query2); if (mysql_num_rows($query2) == 0) { echo "No comments on this topic... yet. Please feel free to leave one <a href='index.php?p=blog&p=comment&pid='" . $row99['pid'] . "'>Here</a>!"; echo "</td></tr></table>\n"; }else{ echo "Place a post <a href='index.php?p=blog&p=comment&pid='" . $row99['pid'] . "'>Here</a>!"; } while ($row2 = mysql_fetch_assoc($query2)) { $id3 = $row2['id']; $pid = $row2['pid']; $pid.= $row['id']; $name2 = $row2['name']; $email2 = $row2['email']; $comm = $row2['comment']; $date2 = $row2['date']; $time2 = $row2['time']; echo "<table width='60%'><tr><td><b>Posted by: " . $name2 . "(" . $email2 . ") at " . $time2 . " on " . $date2 . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(wordwrap($comm, 118, "<br />", true)))); } } echo $paginator; echo "<hr />\n"; echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>\n"; ?>[/code] This is the actual main page of it. Quote Link to comment https://forums.phpfreaks.com/topic/180450-comments-section-on-blog/#findComment-951985 Share on other sites More sharing options...
mikesta707 Posted November 5, 2009 Share Posted November 5, 2009 im assuming this is the link you are talking about echo "...<a href='./index.php?p=blog&p=post&id=" . $id2 . "'>Read More</a><hr /> and its supposed to go to the blog page and show the full post. Well one problem I see is you define to p variables in the GET array. here: p=blog&p=post perhaps that should be different Quote Link to comment https://forums.phpfreaks.com/topic/180450-comments-section-on-blog/#findComment-951990 Share on other sites More sharing options...
Noskiw Posted November 5, 2009 Author Share Posted November 5, 2009 No, I have tested that and it works fine. Trust me. They may use the same variable for loading the dynamic page, but it works. I've done it several times. Quote Link to comment https://forums.phpfreaks.com/topic/180450-comments-section-on-blog/#findComment-951991 Share on other sites More sharing options...
Noskiw Posted November 5, 2009 Author Share Posted November 5, 2009 bump.... Quote Link to comment https://forums.phpfreaks.com/topic/180450-comments-section-on-blog/#findComment-952034 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.