Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Yep It's Me Again >.>


12 replies to this topic

#1 HmmZ

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 362 posts
  • Location:The Netherlands

Posted 31 March 2005 - 07:07 AM

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:
<?php

function 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 :|

#2 Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 31 March 2005 - 09:28 AM

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.

#3 Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 31 March 2005 - 09:31 AM

Er, sorry, line 11, not 9.

#4 HmmZ

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 362 posts
  • Location:The Netherlands

Posted 31 March 2005 - 11:37 AM

Yep, forgot the } one the first part, any suggestions on the second part? (main.php)

#5 Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 31 March 2005 - 11:46 AM

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'.

#6 HmmZ

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 362 posts
  • Location:The Netherlands

Posted 31 March 2005 - 01:10 PM

So what would be a proper way of signaling the end of it then?

#7 Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 31 March 2005 - 01:43 PM

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.

#8 HmmZ

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 362 posts
  • Location:The Netherlands

Posted 31 March 2005 - 02:34 PM

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&amp;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 :)

#9 HmmZ

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 362 posts
  • Location:The Netherlands

Posted 31 March 2005 - 11:14 PM

*BUMP*

please respond? I rewrote the whole thing and i still have the error :)

#10 Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 01 April 2005 - 12:18 AM

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.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users