Jump to content

2 tables wont display


jagguy

Recommended Posts

ok I am getting an error over something simple, can anyone help

Also how do i delete previous threads that I dont wont to continue?

 

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Post.user_id' in 'on clause'

SQL Query: SELECT `Post`.`id`, `Post`.`title`, `Post`.`body`, `Post`.`created`, `Post`.`modified`, `User`.`two`, `User`.`three`, `User`.`id` FROM `jagguy`.`posts` AS `Post` LEFT JOIN `jagguy`.`users` AS `User` ON (`Post`.`user_id` = `User`.`id`) WHERE 1 = 1


class User extends AppModel
{
public $hasMany = 'Post';
}

class Post extends AppModel
{
/*var $name='User';*/
public $belongsTo = array('User');
}

controller
////
class PostsController extends AppController
{

public function home2()
{

$everything= $this->Post->find('all', array('contain' => array('User')));
}

view
<?php foreach ($everything as $item):
echo '<tr><td>'. $item['Post']['id']. '</td>';
echo '<td>'. $item['Post']['title'].'</td>';
echo '<td>'. $item['Post']['body'].'</td>';

Link to post
Share on other sites

The error is self explanatory.

 

 

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Post.user_id' in 'on clause'

For the ON clause you are referring to a column called  user_id  from a table called  Post  in your database. MySQL cannot find that column in that table and this is why you are getting that error. Make sure you have supplied the correct table/column names.

 

 

 

Also how do i delete previous threads that I dont wont to continue?

You cannot delete topics/posts. Only admins/mods can delete topics/posts. We do not reponds to requests for topics/posts to be deleted unless they are against the forums Rules and ToS

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