开发者

zend db select join help

so I have this code:

$sql = new Zend_Db_Select($db);
$sql->from("j");
$sql->join("k","k.id = 开发者_如何学编程j.id",array());
echo $sql;

which results in the query:

SELECT `j`.* FROM `j` INNER JOIN `k` ON k.id = j.id

but I don't just want j.*

I also want k.*

how do I specify zend_db_select for this?


The third parameter for join() is columns for select. You have passed an empty array.

$sql = new Zend_Db_Select($db);
$sql->from('j');
$sql->join('k','k.id = j.id',array());
echo $sql;

Note: for this condition k.id = j.id you should use LEFT JOIN(->joinLeft(...))


You can specify the columns in the from method.

$sql->from(array("j" => "j", array("j.*" , "k.*");

Honestly I am not entirely sure but the Zend Documentation says so :)


if you also want k.*, I think you should have
$sql->join("k","k.id = j.id");, without that array() as the third parameter.
From what I know, that third parameter specifies the columns to be selected from k and since you passed an empty array I'm guessing you override that default k.*


You explicitly tells the join that you want no columns returned for k when you pass an empty array to it. Instead use:

$sql = new Zend_Db_Select($db);
$sql->from('j');
$sql->joinLeft('k','k.id = j.id');
echo $sql;

That should produce what you want I think.


$sql=new Zend_Db_Select($db);
$sql->from('j',array(
//here fields you want to get from 'j' Ex. 'j.id'
));
$sql->join('k',
// here your condition
'k.id = j.id',
//here the fields you need from 'k'
array(
//now the array is empty!!You need to specify needed fields.
//Or just remove it.Defaults is "k.*"!

));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜