Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-01-2007, 05:04 AM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default Joins within Zend_db_table

I'm currenlt trying to do something like this:

Model - products.php
-----------------------------------------------------------------------------------------
class products extends Zend_Db_Table {}

$products = new products();
$db = Zend::registry('db');
$select = $db->select();
$select->from('products', '*');
$select->joinLeft('productFormat', 'productFormat.id = products.productFormatId', '*');
return $products->fetchAll($select);

------------------------------------------------------------------------------------------
products table has a FK named: productFormatId
productFormat table has an id PK

I need to find out how to use and extend zend_db_table so that I can still use the $products->fetchAll() within the controller but it will return the joined table.
I'm currently using thye V.7 framework

using what I've got currently - I receive the following error message:
Warning: PDO::quote() expects parameter 1 to be string
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2007, 05:14 AM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default

Hello,

Question. Is not easier to use rather something more simple rather than going to Zend_DB_Table ?

Cause i would personally go better for this:

$field1 = $db->quote($field1);

$field2 = $db->quote($field2);

$sql = "SELECT * FROM `myTbl` ..... LEFT JOIN ...........................";

$result $db->fetchAll($sql);

Try this way and see what's happening.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2007, 05:35 AM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default

Hi Cristian

Thanks for that, great work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2007, 07:37 AM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default

I've done this:

in the controller:
-----------------------------------------------
$db = Zend::registry('db');
$sql = $db->select();
$sql->from('products', '*');
$sql->join('product_format', 'products.product_format_id = product_format.id', '*');
$view->productsList = $db->fetchAll($sql);
-----------------------------------------------

in the view:
-----------------------------------------------
<?php foreach($this->productsList as $product) : ?>
<option value="<?php echo $this->escape($product->id);?>"><?php echo $this->escape($product->productDesc) . ' - ' . $this->escape($product->productFormatDesc);?></option>
<?php endforeach; ?>
-----------------------------------------------

and I'm receiving an error:
Trying to get property of non-object in product_search.php on line 11

I just can't figure it out - where am I going wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2007, 08:46 AM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default

it's cool - I don't know how I missed that

<?php foreach($this->productsList as $product) : ?>
<option value="<?php echo $this->escape($product['product_code']);?>"><?php echo $this->escape($product['product_desc']) . ' - ' . $this->escape($product['product_format_desc']);?></option>
<?php endforeach; ?>

is there any way that you can get around the name clashes for ID on both tables?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:00 AM.