douchengchen7959 2017-03-09 17:18
浏览 72

查询两个Joomla3 / Virtuemart3表并获取字段值的代码

My SQL and php skills are very limited especially when it comes to Joomla. For at least a day now I am trying to write a query for two Joomla3 Virtuemart3 tables and get the datas but I cannot. The tables are #__virtuemart_order_userinfos and #__virtuemart_orders common fields for both are the virtuemart_order_id the fields that I need, to start with, from the two tables are:

  1. __virtuemart_order_userinfos :

    virtuemart_order_id company last_name first_name

  2. __virtuemart_orders :

    virtuemart_order_id order_number order_total

The rest I can add, I think....

I probably need to have a JOIN for the two tables and select the correct fields based on virtuemart_order_id

Could you write for me the code for Joomla so I can add it to a php file I have created for Invoice and Receipt?

Thank you in advance

  • 写回答

1条回答 默认 最新

  • doxd96148 2017-03-10 06:19
    关注

    please try the query below in joomla ..

    $db = JFactory::getDbo();

    $query = $db->getQuery(true);

    $query->select(array('a.virtuemart_order_id','a.order_total','a.order_number', 'b.company', 'b.last_name','b.first_name'))

    ->from($db->quoteName('#__virtuemart_orders', 'a'))

    ->join('Left', $db->quoteName('#__virtuemart_order_userinfos', 'b') . ' ON (' . $db->quoteName('a.virtuemart_order_id') . ' = ' . $db->quoteName('b.virtuemart_order_id') . ')');

    $db->setQuery($query);

    $results = $db->loadObjectList();

    You can also apply conditions in where clause or can use order clause for ordering for the result. please check the link for further guidance - https://docs.joomla.org/Selecting_data_using_JDatabase

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大