Jump to content

[SOLVED] stuck on MySQL query...


ohdang888

Recommended Posts

$mb = mysql_query("SELECT * FROM `message_board`,`message_read` WHERE `message_board.per_code`='$rep_p' AND

(`message_board.state`='$rep_state' OR `message_board.state`='ALL') AND (`message_read.u_id`!='$user' AND `message_read.m_id` != `message_board.id`) ")or die(mysql_error());

 

Unknown column 'message_board.per_code' in 'where clause'

 

but i assure, all of all is spelled correctly, and yes, a column of "per_code" actually exists in the table of "message_board"

 

any ideas?thanks!

Link to comment
Share on other sites

You must of typed something incorrectly. Double check to make sure everything is spelled correctly (your query and your database). You may have made a mistake when creating the table/columns in the database, for example per_code may be typed like par_code something silly like that.

 

Also avoid using SELECT * in your query. List your columns.

Link to comment
Share on other sites

CREATE TABLE `message_board` (

  `id` int(11) NOT NULL auto_increment,

  `per_code` int(2) NOT NULL,

  `message` varchar(500) NOT NULL,

  `by` bigint(20) NOT NULL,

  `state` varchar(2) NOT NULL,

  `date` varchar(20) NOT NULL,

  PRIMARY KEY  (`id`),

  UNIQUE KEY `id` (`id`)

)

 

and

 

CREATE TABLE `message_read` (

  `id` int(11) NOT NULL auto_increment,

  `m_id` int(11) NOT NULL,

  `u_id` bigint(20) NOT NULL,

  PRIMARY KEY  (`id`),

  UNIQUE KEY `id` (`id`)

)

 

those are the tables, the SQL just exported... unless i'm blind, which i could be, there's nothing misspelled

Link to comment
Share on other sites

Doh! Just noticed whats up, it's to do with the backticks

 

MySQL is trying to find a column called message_board.per_code not the column per_code within the message_board table.

This:

`message_board.per_code`

should be witten as

`message_board`.`per_code`

Only the table/column name needs to be in backticks not the period.

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.