是的,我得到了这个工作,但由于某种原因我的循环仍然显示错误的值......
$db = JFactory::getDBO();
$query = "select * from jos_gerencia_vendas AS a LEFT JOIN jos_gerencia_clientes AS b ON b.Id=a.id_cliente where a.id_edicao = ".$iddaedicao." order by b.nomecliente ASC";
$db->setQuery($query);
$list = $db->loadObjectList();
foreach ($list as $item)
{
$Id = $item->Id;
$id_venda = $item->id_venda;
$id_edicao = $item->id_edicao;
$id_vendedor = $item->id_vendedor;
$id_cliente = $item->id_cliente;
$id_produto = $item->id_produto;
$data_insercao = $item->data_insercao;
$pagina = $item->pagina;
我需要从foreach循环中的jos_gerencia_vendas中检索$ Id变量,任何线索?
答案 0 :(得分:0)
如果两个表上都有一个名为Id的列,那么当你获得$ item->时,Id将是不明确的。你可以在mysql控制台或phpmyadmin上运行查询,看它是否抛出任何错误吗?
答案 1 :(得分:0)
您可以使用别名从查询中检索信息,如
$query = "select a.id as id,a.col1 as id_venda,a.col2 as id_edicao,b.col1 as id_vendedor from jos_gerencia_vendas AS a LEFT JOIN jos_gerencia_clientes AS b ON b.Id=a.id_cliente where a.id_edicao = ".$iddaedicao." order by b.nomecliente ASC";
$db->setQuery($query);
$list = $db->loadObjectList();
foreach ($list as $item)
{
$Id = $item->Id;
$id_venda = $item->id_venda;
$id_edicao = $item->id_edicao;
$id_vendedor = $item->id_vendedor;