[英]Code to Query two Joomla3 / Virtuemart3 tables and get field values
My SQL and php skills are very limited especially when it comes to Joomla. 我的SQL和PHP技能非常有限,尤其是在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.
现在至少有一天,我正在尝试为两个Joomla3 Virtuemart3表编写查询并获取数据,但我做不到。 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:
这些表是#__virtuemart_order_userinfos和#__virtuemart_orders的公用字段,这两个字段都是我需要从两张表开始的containermart_order_id字段:
virtuemart_order_id company last_name first_name 美德马车公司ID公司的姓氏first_name
virtuemart_order_id order_number order_total 德意志超市ID订单编号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 我可能需要为两个表加入一个JOIN,然后根据containermart_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? 您能为我写Joomla的代码,以便将其添加到为发票和收据创建的php文件中吗?
Thank you in advance 先感谢您
please try the query below in joomla .. 请尝试在joomla中查询以下内容。
$db = JFactory::getDbo(); $ db = JFactory :: getDbo();
$query = $db->getQuery(true); $ 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')) $ 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')) ->从($ 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') . ')'); -> join('Left',$ db-> quoteName('#__ virtuemart_order_userinfos','b')。'ON('。$ db-> quoteName('a.virtuemart_order_id')。'='。$ db-> quoteName('b.virtuemart_order_id')。')');
$db->setQuery($query); $ DB-> setQuery($查询);
$results = $db->loadObjectList(); $ results = $ db-> loadObjectList();
You can also apply conditions in where clause or can use order clause for ordering for the result. 您还可以在where子句中应用条件,也可以使用order子句对结果进行排序。 please check the link for further guidance - https://docs.joomla.org/Selecting_data_using_JDatabase
请检查链接以获取更多指导-https: //docs.joomla.org/Selecting_data_using_JDatabase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.