dougan4663 2015-12-23 09:15 采纳率: 0%
浏览 71

自定义查询中的Joomla 3 Zoo组件JSON提取

I am using zoo component for items and just moved Joomla from 1.5 to 3 version and Zoo component changed their format to save items

On the Previous version, zoo component was using XML format to save the data in the database and now in the new version, they are using JSON format.

Now, let me come to the issue:

I have developed custom module for fetching data where the query is like:

SELECT DISTINCT id, name FROM #__zoo_item WHERE application_id=1 and state=1 and type='abo' AND ExtractValue(elements,'/elements/relateditems[@identifier="9264aa8aa-6b39-4ecc-969a-f17da2688a5c"]/item')=24 ORDER BY ExtractValue(elements,'/elements/radio[@identifier="3dd960814e-b3f9-4ca2-abdb-070d0f51e7b9"]/option') ASC, FIELD(ExtractValue(elements,'/elements/radio[@identifier="86c0c108-8a31-48b9-badb-857ss7f359c1b7"]/option'),'ja','regal','ntein') ,ExtractValue(elements,'/elements/radio[@identifier="3960814e-b3f9-4ca2-abdb-070d0f51epp7b9"]/option') DESC

Here in the query used ExtractValue function of MySQL to match the extracted value from the XML.

Here is the XML format:

<?xml version="1.0" encoding="utf-8"?>
<elements>
<select identifier="9d534d17-d6d9-4671-a7d1-0b1f8ec71f07">
  <option><![CDATA[salt]]></option>
</select>
<relateditems identifier="9264aa8aa-6b39-4ecc-969a-f17da2688a5c">
  <item><![CDATA[24]]></item>
</relateditems>
<text identifier="b44baf4c-bbb0-4410-a12c-23ec3b7ba5d6">
  <value><![CDATA[]]></value>
</text>
<text identifier="c3903e1e-bc09-4708-bf8f-dc765a84ccd4">
  <value><![CDATA[]]></value>
</text>
<image identifier="4079ccd8-04df-41fd-b41e-52c23351a215">
  <file><![CDATA[test.png]]></file>
  <title/>
  <link/>
  <target/>
  <rel/>
  <lightbox_image/>
  <width><![CDATA[100]]></width>
  <height><![CDATA[80]]></height>
</image>
<radio identifier="86c0c108-8a31-48b9-badb-857ss7f359c1b7">
  <option><![CDATA[ja]]></option>
</radio>
<radio identifier="3960814e-b3f9-4ca2-abdb-070d0f51epp7b9">
  <option><![CDATA[0]]></option>
</radio>
</elements>

Now, Issue is how can I use a query which check matched extracted value in JSON format. Also, MySQL version is 5.5 so latest 5.7 JSON Functions are not working.

Here is the JSON Format:

{
    "9264aa8aa-6b39-4ecc-969a-f17da2688a5c":  {
        "item":  {
                "0": "8665"
        }
    },
        "50b019d0-6e30-4a27-a46c-68dbe5ade18b":  {
        "0":  {
            "value": "GRUNDGEB\u00dcHR: CHF 59.00|
ANRUFE: Unlimitiert in der Schweiz|
SMS\/MMS: Unlimitiert in der Schweiz|
INTERNET 4G: Unlimitiert in der Schweiz|"
        }
    },
    "3dd960814e-b3f9-4ca2-abdb-070d0f51e7b9":  {
        "option":  {
            "0": "salt"
        },
        "select": "1"
    },
    "26112e4c-83c5-4e38-806b-fccfb7f8aa69":  {
        "votes": 0,
        "value": 0
    },
}

Anyone has the idea how to check in JSON data? Any MySQL function work in this?

  • 写回答

1条回答 默认 最新

  • dshdb64088 2015-12-23 11:36
    关注
    <?php
    $db = JFactory::getDbo();   
     $query = $db->getQuery(true);
     $query->select($db->quoteName(array('64ccc68f-4af3-4c02-8c0f-8ec5977bacb2')))
      ->from($db->quoteName('#__zoo_item'))
      ->where($db->quoteName('application_id') . ' = 1 AND '. 
              $db->quoteName('state')  . ' = 1 AND '. 
              $db->quoteName('type')  . ' = ' $db->quoteName('handy'));
    
      $db->setQuery($query);  
      $results = $db->loadObjectList(); 
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看