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