Jump to content


Photo

solved WHERE ... syntax


  • Please log in to reply
10 replies to this topic

#1 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 21 August 2006 - 04:31 AM

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

"SELECT news.newsID, news.authorID AS newsAuthor, 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 " .
"WHERE newsAuthor = 1";

$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!

#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 21 August 2006 - 08:49 AM

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


#3 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 21 August 2006 - 03:35 PM

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

#4 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 21 August 2006 - 03:42 PM

Post the create statement for the "news" table using the following query.
SHOW CREATE TABLE news


#5 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 21 August 2006 - 03:59 PM

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

#6 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 21 August 2006 - 04:06 PM

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.
SELECT `news`.`id` FROM ...


#7 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 21 August 2006 - 04:17 PM

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!

#8 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 21 August 2006 - 04:23 PM

what does it mean when you get this error from mysql_error()?
MySQL server has gone away

#9 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 21 August 2006 - 04:29 PM

http://dev.mysql.com.../gone-away.html

#10 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 August 2006 - 05:38 PM

Or you could just not use backticks at all....
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#11 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 21 August 2006 - 09:02 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users