Jump to content
xisto Community
Sign in to follow this  
HmmZ

Yep It's Me Again >.> This time with news

Recommended Posts

Yea you heard it, im back but this time with something else...news, as in, displaying news :)

I found a great guide on how to basically create a news system (the point is that i could use a CMS, but I wanna do everything myself....with help B) )

Anyway, back to the topic, I'm getting weird errors in a few of my files:

<?phpfunction displayOneItem($id){  global $db;  $query="select * from news where id=$id";  $result=mysql_query($query);  if(mysql_num_rows($result)==0){   echo "<td align=\"center\">Bad news id</td>\n";   return;   $row=mysql_fetch_assoc($result);   echo "<table border=\"1\" width=\"300\">\n";  $title=htmlentities($row['title']);  $news=nl2br(strip_tags($row['newstext'],'<a><b><i><u>'));   echo "<TR><TD><b>$title</b></td></tr>\n";   echo "<TR><TD>$news</td></tr>\n";   echo "</table>\n";   echo "<br>\n";  displayComments($id);}?>
with the error:
Parse error: parse error, unexpected $ in /home/ridouan/public_html/News/item.php on line 26

But, according to the guide, the displayComments($id); is a necessary line???Hhelp :)

ill make a shorter second, for the sake of clear reading >.>
in my main file im getting a t_string error:
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/ridouan/public_html/News/main.php on line 64

you can find the full code here

Fortunately, the other 3 files (addcomment, comment and news) are seeming to work properly (no errors when I run them), hopefully someone can help here :|

Share this post


Link to post
Share on other sites

You aren't finalizing the if() statement. Place a closing brace } after 'return;' on line 9. That is the most likely cause of the errors that I can see. Does it say 'unexpected $', or 'unexpected $end'? The later means an if(), while(), etc statement or a function hasn't been closed correctly, and the PHP engine isn't expecting to reach the end of the script.

Share this post


Link to post
Share on other sites

On line 56, you have:

echo "<br>n\";
This will cause the final quotation mark to become part of the string, rather than signal the end of it, so it is still assuming that everything thereafter is to be included in the string being sent to 'echo'.

Share this post


Link to post
Share on other sites

I'm assuming you want it to be \n. So change it to echo "<br>\n";. A string is indicated by a value between two quotation markes - single or double (you can use either, as long as it is consistent in assigning the value - you can't start it with a single quote, and end it with a double). A backslash indicates a literal character - so in this case, it would add the double quote to the string, and cause everything from there until the next standalone double quote to become apart of the string.I'm a little tired to be explaining things, but you should get the idea.

Share this post


Link to post
Share on other sites

I'm truly sorry that im bugging you so much, but I am learning alot now :/. now, hopefully the last one (sorry!)

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/ridouan/public_html/News/main.php on line 15

I've been googling a bit to hope and save you the trouble, but I couldn't find anything relevant :)

function displayNews($all=0){  global $db,$max_items; if($all==0){  $query="select id,title,newstext,"."date_format(postdate, '%Y-%m-%d') as date"."from news order by postdate desc limit $max_items";} else {  $query="select id,title,newstext,"."date_format(postdate, '%Y-%m-%d') as date"."from news order by postdate desc";  }  $result=mysql_query($query);  while ($row=mysql_fetch_assoc($result)){   echo "<table border=\"1\" width=\"300\" align=\"center\">\n";  $date=$row['date'];  $title=htmlentities($row['title']);  $news=nl2br(strip_tags($row['newstext'],'<a><b><i><u>'));   echo "<TR><TD><b>$title</b> posted on $date</td></tr>\n";   echo "<TR><TD>$news</td></tr>\n";  $comment_query="select count(*) from news_comments"."where news_id={$row['id']}";  $comment_result=mysql_query($comment_query);  $comment_row=mysql_fetch_row($comment_result);   echo "<TR><TD><a href=\"{$_server['php_self']}"."?action=show&id={$row['id']}\">Comments</a>"."($comment_row[0]}</td></tr>\n";   echo "</table>\n";   echo "<br>\n";} if($all==0){   echo "<a href=\"{$_server['php_self']}"."?action=all\">View all news</a>\n";}}

I sincerely hope this is my last question for you :)

Share this post


Link to post
Share on other sites

Please don't bump posts. Someone will get around to answering them when they have the time.The error you are receiving is a result of a previous MySQL query not completing successfully or not returning a result. I'll assume this is on the line '$result=mysql_query($query);', meaning that the query contained within the $query variable is not valid or is not returning anythng. Try adding some more error detection/prevention.

Share this post


Link to post
Share on other sites

i would like to suggest that you make sure that your sql queries are correct. that error usually shows up when the function mysql_query() return a value of false which is not a valid resource. this happens because of errors in sql queries.

Share this post


Link to post
Share on other sites

Ive checked all the queries numberous times but I can't find the error, also, i have a file (news.php) wich has the EXACT same code of displayNews and that one is NOT showing errors....please, could it be anything else?

Share this post


Link to post
Share on other sites

i really think that the problem is in the mysql_query() function. is $db your connection id to mysql? like you used it like $db = mysql_conect()? so why not do the query like this? if ever there is an error in the query, surely it will be shown completely.

function displayNews($all = 0) {	global $db, $max_items;		if ($all == 0) {  $query = "SELECT id, title, newstext, date_format(postdate, \'%Y-%m-%d\') as date   	FROM news   	ORDER BY postdate DESC  	LIMIT $max_items";	} else {  	$query = "SELECT id, title, newstext, date_format(postdate, \'%Y-%m-%d\') as date   	FROM news   	ORDER BY postdate DESC";  }		if (!($result = mysql_query($query, $db))) {  exit('MySQL Query Error: ' . mysql_error() . ' | SQL Query: ' . $query . ' | Line: ' . __LINE__);	}		while ($row = mysql_fetch_assoc($result)) {  $date = $row['date'];  $title = htmlentities($row['title']);  $news = nl2br(strip_tags($row['newstext'], '<a><b><i><u>'));    echo "<table border=\"1\" width=\"300\" align=\"center\">\n";  echo "<TR><TD><b>$title</b> posted on $date</td></tr>\n";  echo "<TR><TD>$news</td></tr>\n";    $comment_query = "SELECT count(*)   	FROM news_comments  	WHERE news_id={$row['id']}";    if (!($comment_result = mysql_query($query, $db))) {  	exit('MySQL Query Error: ' . mysql_error() . ' | SQL Query: ' . $comment_query . ' | Line: ' . __LINE__);  }    $comment_row = mysql_fetch_row($comment_result);    echo "<TR><TD><a href=\"{$_server['php_self']}"."?action=show&id={$row['id']}\">Comments</a>"."($comment_row[0]}</td></tr>\n";  echo "</table>\n";  echo "<br>\n";	}		if ($all == 0 ) {  echo "<a href=\"{$_server['php_self']}?action=all\">View all news</a>\n";	}}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.