Jump to content

solved WHERE ... syntax


chico1st

Recommended Posts

something is wrong with my WHERE statement :S This looks right to me

"SELECT news.newsID, [b]news.authorID AS newsAuthor[/b], news.topicID AS newsTopic, news.name AS newsName, news.abstract, " .
"news.fulltext, date.name AS date, topic.name AS topic, author.name AS author " .
"FROM news, date, topic, author " .
[b]"WHERE newsAuthor = 1";[/b]

$result = mysql_query($query) or die('Error, query failed');

I get 'Error, query failed'
there is an entry that matches this but it shouldnt say that even if there isnt an entry

Thanks for any help you may offer!
Link to comment
https://forums.phpfreaks.com/topic/18163-solved-where-syntax/
Share on other sites

ok wow.. that mysql_error() thing is amazing i wish i knew about that before

SELECT `news.newsID`, `news.authorID`, `news.topicID`, `news.name`, `news.abstract`, `news.fulltext`, `date.name` FROM `news`, `date`
Unknown column 'news.newsID' in 'field list'

newsID is definatly a field in my news table
Link to comment
https://forums.phpfreaks.com/topic/18163-solved-where-syntax/#findComment-78123
Share on other sites

CREATE TABLE `news` (\n  `newsID` smallint(4) NOT NULL auto_increment,\n  `dateID` varchar(5) NOT NULL,\n  `authorID` smallint(4) NOT NULL,\n  `topicID` varchar(4) NOT NULL,\n  `pictureID` varchar(4) NOT NULL,\n  `name` varchar(20) NOT NULL,\n  `fulltext` longtext NOT NULL,\n  `abstract` tinytext NOT NULL,\n  PRIMARY KEY  (`newsID`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1
Link to comment
https://forums.phpfreaks.com/topic/18163-solved-where-syntax/#findComment-78133
Share on other sites

I should have noticed this before.

If the entire value is surrounded by backticks (`) then it's assumed to be a column name in that context. You can either remove the backticks or surround the table name and column name individually with backticks.
[code]
SELECT `news`.`id` FROM ...
[/code]
Link to comment
https://forums.phpfreaks.com/topic/18163-solved-where-syntax/#findComment-78134
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.