doufuxing8691 2012-08-22 21:56
浏览 10
已采纳

我的joomla问题离开了加入mysql

right i got this working but for some reason my loop still showing the wrong values...

$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;

i need to retrieve the $Id variable from the jos_gerencia_vendas inside the foreach loop, any clue?

  • 写回答

2条回答 默认 最新

  • ds08541 2012-08-23 17:14
    关注

    You can use alias to retrieve information from the query like this

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?