Jump to content

editing existing code


razzle

Recommended Posts

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)

 

 

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.