0

对,我得到了这个工作,但由于某种原因,我的循环仍然显示错误的值......

$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 变量,有什么线索吗?

4

2 回答 2

0

如果您在两个表上都有一个名为 Id 的列,那么当您获得 $item->Id 时将是模棱两可的。您能否在 mysql 控制台或 phpmyadmin 上运行查询以查看它是否抛出任何错误?

于 2012-08-23T02:40:26.830 回答
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;
于 2012-08-23T17:14:09.377 回答