Jump to content

Recommended Posts

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

 

1.jpg

 

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!

 

Link to comment
https://forums.phpfreaks.com/topic/240684-kohana-2-mysql-error/
Share on other sites

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?

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.