razzle Posted December 1, 2007 Share Posted December 1, 2007 ok guys im not going to pretend im good with php so let me cut to the chase i used this tutorial to create a news page with comments, but there are some things id like to change or tweek about how it works. here is the tutorial http://www.tutorialcode.com/php/news-system-with-comments/ ive got my working version of it on my site www.pushmusic.org or here is the direct link http://www.pushmusic.org/archive/news.php ok so ....... i want to make the news page display only the latest 10 articals, and perhaps have a series of pages for previous news each displaying 10 posts, do you know what i mean? id also like a way of deleting or editing the comments posted by readers just in case someone writes something offensive. and if someones feeling really creative.... id like to be able to display the title of the latest news artical on my main page, at the moment my main page just displays a link to the news, id like that to display the latest news artical. any help would be greatly appritaited many thanks ben (please excuse my spelling mistakes) Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 You can LIMIT the number of articles to get in a query. You can use $_GET to make links to edit or delete each row in the DB. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 1, 2007 Share Posted December 1, 2007 Is this a paid gig? = ^) PhREEEk Quote Link to comment Share on other sites More sharing options...
razzle Posted December 1, 2007 Author Share Posted December 1, 2007 @revraz im sorry im a real novice ,where would i the code to limit the muber of articals? <html> <head> <script type="text/javascript"> function openComments(url) { comments = window.open(url, "Comment", "menubar=0,resizable=0,width=380,height=480") comments.focus() } </script> </head> <body> <?php include ('mysql_connect.php'); $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts"; $result = @mysql_query($query); if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $url = 'comments.php?id='.$row['id']; echo '<p><b>'.$row['title'].'</b><br /> '.$row['sd'].'<br /> Posted by : <b>'.$row['author'].'</b><br /> '.$row['post'].'<br /> <a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>'; } } else { echo 'There are no news posts to display'; } ?> </body> </html> can you show me how i would do it? and @PhREEEk do you mean did I pay or will I pay? cos i haven't really got the capital to pay someone to sort it for me, would be nice if i did though Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 You can put it in your mysql query http://php.about.com/od/mysqlcommands/g/Limit_sql.htm Quote Link to comment Share on other sites More sharing options...
razzle Posted December 1, 2007 Author Share Posted December 1, 2007 so i could put $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts" LIMIT 0, 10; as apposed to $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts"; and that would give me only the latest 10 posts, ok so whats the best way of creating pages for the 10 posts before that? my minds telling me to create a new file called news2.php and use this line $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts" LIMIT 10, 10; but then i would have to create loads of pages link that as my news archive grows, am i being a simpleton? or is the way its done? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 May want to use pagination for multiple pages. There is a tutorial for it here in the tutorial section. Quote Link to comment Share on other sites More sharing options...
razzle Posted December 1, 2007 Author Share Posted December 1, 2007 http://php.about.com/od/phpwithmysql/ss/php_pagination.htm is this what i need? Quote Link to comment Share on other sites More sharing options...
razzle Posted December 1, 2007 Author Share Posted December 1, 2007 lol you already answered that question Quote Link to comment Share on other sites More sharing options...
razzle Posted December 2, 2007 Author Share Posted December 2, 2007 ok i thin ig to the pagination sorted on my site can any one point me in the direction of a tutorial which will be able to place the latest news headline on my index page? ive searched in google but im not sure im using the right tearms to describe what i want can abyone help me? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 2, 2007 Share Posted December 2, 2007 You've already showed how to do that up in your reply $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts" LIMIT 0, 10; Just change it to display the last news entry, so ORDER BY date DESC limit 0, 1 Quote Link to comment Share on other sites More sharing options...
razzle Posted December 2, 2007 Author Share Posted December 2, 2007 i did warn you that i was a newbie, haha i was thinking i should be pulling info from my php pages rather than the database itself im an idiot cheers mate Quote Link to comment Share on other sites More sharing options...
revraz Posted December 2, 2007 Share Posted December 2, 2007 No problem, I'd rather make you think about how to do it rather than do it for ya Quote Link to comment Share on other sites More sharing options...
razzle Posted December 2, 2007 Author Share Posted December 2, 2007 do you think you can help me with this check the page im on about http://www.pushmusic.org/archive/news.php ok under every news post is a link to a comments page for each individual article how would i go about making this link dynamic ie it shows how many comments there are already? example - add new comments or read existing comments (3) as opposed to what i have now which is the above without the "(3)" the way my comments database is set us is like this CREATE TABLE comments ( id INT(11) NOT NULL AUTO_INCREMENT, nid INT(11) NOT NULL, title VARCHAR(70) NOT NULL, author VARCHAR(50) NOT NULL, comment TEXT NOT NULL, DATE DATETIME NOT NULL, PRIMARY KEY (id) ); where id is the comment id and nid is the id of the news article on a separate database here is the code on my news.php page <?php include ('mysql_connect.php'); $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts"; $result = @mysql_query($query); if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $url = 'comments.php?id='.$row['id']; echo '<p><b>'.$row['title'].'</b><br /> '.$row['sd'].'<br /> Posted by : <b>'.$row['author'].'</b><br /> '.$row['post'].'<br /> <a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>'; } } else { echo 'There are no news posts to display'; } ?> now im sure i need to set a variable but what sort of function do i need your help would be greatly appritiated Quote Link to comment Share on other sites More sharing options...
razzle Posted December 2, 2007 Author Share Posted December 2, 2007 ok i think i need to use the mysql_num_rows function can some one show me how to display the ammount of comments there are if you look at the post above you will see two coulombs we need to use id and nid where id is the id of the comment and nid is the id from an artical in a seperate news db i think i need something like this $sql = mysql_query("SELECT id, nid FROM comments WHERE id='$nid'")or die(mysql_error()); $sql_num_rows = mysql_num_rows($sql); echo "add new comment or read existing comments ($sql_num_rows)"; does this make sense to anyone, or does it need changing? many thanks Quote Link to comment Share on other sites More sharing options...
razzle Posted December 2, 2007 Author Share Posted December 2, 2007 please please please will someon help me im begging i think im right on the verge of getting it right but i just cant see whats gone wrong <?php include ('mysql_connect.php'); $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC"; $result = @mysql_query($query); if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)); $num = $row['id']; $sql = mysql_query("SELECT id FROM comments WHERE id='$num'")or die(mysql_error()); $sql_num_rows = mysql_num_rows($sql); { $url = 'comments.php?id='.$row['id']; echo '<p align="center"><b>'.$row['title'].'</b><br /> '.$row['sd'].'<br /> Posted by : <b>'.$row['author'].'</b><br /> '.$row['post'].'</p><p span class="style2" align="right"> <a href="'.$url.'">Add new comment or view posted comments ('.$sql_num_rows.')</a></p><p span class="style1" align="center"><hr width="90%" /></p>' ; } } else { echo 'There are no news posts to display'; } ?> its not throwning up an error, but its not showing any of the articals, ironicly the mysql_num_rows function is working. can someone help me to get this to work all together Quote Link to comment Share on other sites More sharing options...
razzle Posted December 2, 2007 Author Share Posted December 2, 2007 managed it on my lonesome now guys cheers to everyone whos helped me particularly revraz Quote Link to comment 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.