Jul 25, 2008

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

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming
Pages: 1, 2

free web hosting

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

HmmZ
Yea you heard it, im back but this time with something else...news, as in, displaying news sleep.gif

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 sad.gif )

Anyway, back to the topic, I'm getting weird errors in a few of my files:
CODE
<?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:
CODE
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 sad.gif

ill make a shorter second, for the sake of clear reading >.>
in my main file im getting a t_string error:
CODE
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 :|

 

 

 


Reply

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

Reply

Spectre
Er, sorry, line 11, not 9.

Reply

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

Reply

Spectre
On line 56, you have:
CODE
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'.

Reply

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

Reply

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

Reply

HmmZ
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 sad.gif
CODE
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 sad.gif

 

 

 


Reply

HmmZ
*BUMP*

please respond? I rewrote the whole thing and i still have the error sad.gif

Reply

Spectre
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

Latest Entries

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

CODE
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&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";
}
}

Reply

HmmZ
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?

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Similar Topics

Keywords : yep, time, news

  1. Sending E-mails After News Update?
    Coding needed?!? (8)
  2. How Yahoo! Publish News ?
    (3)
    I want to know how the websites like www.myway.com publish news? They do not have their own news ..
    they take from other sources... for example reuters.. most of the news from yahoo are from AP.. of
    course these websites are very big and they have some professional services..but i just want to know
    , how does this work ? What is the way to publish news on website ? Is there any news services
    which allows to print the complete news articles on others website ? Usually rss news prints only
    headlines.. if there is any information about it please let me know.....
  3. News Fetching Script
    (1)
    Im looking for some script which can fetch news from Reuters or any other news website and publish
    on my own webite.(of course i'll mention clearly that it is from reuters or anything else).. I
    dont mean RSS feeds where i can put only headline of some lines and then the link of the news
    website..i mean , for example on front page of my website there will be headlines..and when some one
    click on headline , it opens details of news on my own website, Not on the reutors etc.. Is it
    possible ?....
  4. Php News Script
    how to make news script that uses MySQL writen in PHP (18)
    How to make a News script with PHP + MySQL So..in this tutorial i will explain how to create PHP
    news script. first we have to create the table in My SQL.. with the code below you will do this (
    you have to enter it into SQL field ..in PHPmyADMIN) CODE CREATE TABLE news ( id
    int(10) unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title
    varchar(50) NOT NULL default '', content text NOT NULL, PRIMARY KEY (id),
    KEY postdate (postdate), FULLTEXT KEY content (content) ) >>....
  5. Php Dynamic News Updating Using Mysql
    changing a sites news using MySQL and PHP (3)
    Hey everyone. It appears to me that everyone really know what they are doing in this forum and im a
    pretty new to this PHP and MySQL combo. I know some PHP but not MySQL....I am trying to make a new
    website but i want to be able to go to a certain update page and change the news on the main index.
    For example: - The main page show news updates of the last 10 post. - I go to the update page
    and then fill in the form and it will add this post to the top of the list and still only print the
    top 10. I have no clue how to do this with MySQL. At the moment i am doing it u....

    1. Looking for yep, time, news

Searching Video's for yep, time, news
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE