baldiajaib Posted June 29, 2011 Share Posted June 29, 2011 i'm quite new in kohana 2..ben following a tutorial and error comes out trying to retrieve data from mysql: but error comes out the view page, products.php: <h2>Products</h2> <h3>L33t Products</h3> <table> <tr> <th>Category</th> <th>Product Code</th> <th>Product Description</th> <th>Price</th> <th>Units</th> </tr> <?php foreach ($products as $item): ?> <tr> <td><?php echo html::specialchars($item->cat_description) ?></td> <td><?php echo html::specialchars($item->code) ?></td> <td><?php echo html::specialchars($item->prod_description) ?></td> <td><?php echo number_format(($item->price / 100),2) ?></td> <td>per</td> <td><?php echo html::specialchars($item->unit) ?></td> </tr> <?php endforeach ?> </table> the controller, products.php: <?php defined('SYSPATH') or die('No direct script access.'); class Products_Controller extends Website_Controller { public function index() { $this -> template -> title = 'Products::Kohana 2.0 Tutorial'; $this -> template -> content = new View ('pages/products'); $products = new Product_Model; // instantiate the model //result set is assigned to a variable called $products in the view $this->template->content->products = $products->browse(); /*Line is used to check database whether DB connection is working or not echo Kohana::debug($this->db->list_fields('categories'));*/ } } the model, product.php : <?php defined ('SYSPATH') or die ('No Direct Script Access'); class Product_Model extends Model { public function __construct() { parent::__construct(); } public function browse() { return $this->db->select ( 'categories.description AS cat_description', 'products.code', 'products.description AS prod_description', 'products.price', 'products.unit' ) ->from('categories') ->join('products', 'categories.id = products.cat_id') ->orderby (array('categories.description' => 'ASC', 'products.code' => 'ASC')) ->get(); } } cracked my head for few days now....thanks in advance guys! Quote Link to comment https://forums.phpfreaks.com/topic/240684-kohana-2-mysql-error/ Share on other sites More sharing options...
mikosiko Posted June 29, 2011 Share Posted June 29, 2011 in your product.php file try replacing this line: ->join('products', 'categories.id = products.cat_id') for this ->join('products', 'categories.id', 'products.cat_id') Quote Link to comment https://forums.phpfreaks.com/topic/240684-kohana-2-mysql-error/#findComment-1236385 Share on other sites More sharing options...
baldiajaib Posted June 30, 2011 Author Share Posted June 30, 2011 in your product.php file try replacing this line: ->join('products', 'categories.id = products.cat_id') for this ->join('products', 'categories.id', 'products.cat_id') edited it and it works like a charm...hoever i thought the standard php for joining php was like this example below: $query = "SELECT family.Position, food.Meal ". "FROM family, food ". "WHERE family.Position = food.Position"; anyway thanks man...extremely appreciate your help and time....I almost gave up yesterday....I have another question...how do u exactly read the kohana error? the stack error is used for what? Quote Link to comment https://forums.phpfreaks.com/topic/240684-kohana-2-mysql-error/#findComment-1236629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.