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