Jump to content

Archived

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

chico1st

solved WHERE ... syntax

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!

Share this post


Link to post
Share on other sites
Change the code to the following and post the output.
[code]
$query = 'query here';
$result = mysql_query($query) or die($query."<br />\n".mysql_error());
[/code]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Post the create statement for the "news" table using the following query.
[code]
SHOW CREATE TABLE news
[/code]

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
thanks a tonne! i dont know the syntax of a lot of things like that.. i just kindof toss backticks in when i feel like it.. its bad  but im getting better!

Share this post


Link to post
Share on other sites
what does it mean when you get this error from mysql_error()?
MySQL server has gone away

Share this post


Link to post
Share on other sites
http://dev.mysql.com/doc/refman/4.1/en/gone-away.html

Share this post


Link to post
Share on other sites
Or you could just not use backticks at all....

Share this post


Link to post
Share on other sites
i usually dont but when things go wrong i kind of just throw them in, i used to think it was a good idea.. but now i know
and knowing is half the battle... GI JOE!

Share this post


Link to post
Share on other sites

×

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.