dongqie2028 2018-10-06 15:07
浏览 35

Joomla数据库查询列参数OS事件管理器

I am using OS Events Manager, and I need to show query from a table column to show the "field_speaker" which is the under the params column in OS Events Manager. I have this code: `

$query   = $db->getQuery(true)
->select('a.*')
->from('#__eb_speakers AS a')
->innerJoin('#__eb_events AS b ON a.id = b.speaker_id')
->where('b.event_id = ' . $event->id)
->order('b.id');
$db->setQuery($query);
$speakers = $db->loadObjectList();
print_r($speakers); ?>'

I don't know how to call the column params "field_speaker" as shown in the image I provided... If you look at my code I only have the eb_events-which is where everything is going wrong I guess???

Any help would be greatly appreciated. I know a little PHP-obviously not enough... Samenter image description here

  • 写回答

1条回答 默认 最新

  • dsaf32131 2018-10-08 06:18
    关注

    You seem to be only interested in the params column, so only write that column in the SELECT clause and use loadColumn() to access the data (generate a 1-dimensional array for simpler handling).

    https://docs.joomla.org/Selecting_data_using_JDatabase#Single_Column_Results

    If you want more columns than params, you should name them explicitly in your query, and use a different method to collect the result set. (See the link above)

    My untested suggestion:

    $query = $db->getQuery(true)
                ->select('a.params')                 // only ask for what you intend to use
                ->from('#__eb_speakers AS a')
                ->innerJoin('#__eb_events AS b ON a.id = b.speaker_id')
                ->where('b.event_id = ' . (int)$event->id)   // for security cast as an integer
                ->order('b.id');
    $db->setQuery($query);
    if (!$params = $db->loadColumn()) {
        echo "No Data Found for " . (int)$event->id;
    } else {
        foreach ($params as $param) {
            $speakers[] = json_decode($param, true)['field_speaker']; // I assume this key always exists
        }
    }
    var_export($speakers);  // this will show you the isolated speaker data
    

    p.s. When you have Joomla-based questions, please post them in Joomla Stack Exchange so that that community has some new stuff to chew on.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效