doulongdan2264 2014-12-11 08:14
浏览 199
已采纳

Joomla数据库以及如何提取数据

i have kind of hacked away at a joomla component, it works well with one table, but i was looking at having more than one table, but i cant seem to get it to draw from 2 tables. ie one table will have lets say article information, the other table will have other data relevant to the articles and their id's. Any ideas on how i can do this

  • 写回答

1条回答 默认 最新

  • donglaohua1671 2014-12-12 18:38
    关注

    Selecting Records from Multiple Tables

    Using the JDatabaseQuery's join methods, you can select records from multiple related tables. The generic "join" method takes two arguments; the join "type" (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).

    // Get a db connection.
    $db = JFactory::getDbo();
    
    // Create a new query object.
    $query = $db->getQuery(true);
    
    // Select all articles for users who have a username which starts with 'a'.
    // Order it by the created date.
    // Note by putting 'a' as a second parameter will generate `#__content` AS `a`
    $query
        ->select($db->quoteName(array('a.*', 'b.username', 'b.name')))
        ->from($db->quoteName('#__content', 'a'))
        ->join('INNER', $db->quoteName('#__users', 'b') . ' ON (' . $db->quoteName('a.created_by') . ' = ' . $db->quoteName('b.id') . ')')
        ->where($db->quoteName('b.username') . ' LIKE \'a%\'')
        ->order($db->quoteName('a.created') . ' DESC');
    
    // Reset the query using our newly populated query object.
    $db->setQuery($query);
    
    // Load the results as a list of stdClass objects (see later for more options on retrieving data).
    $results = $db->loadObjectList();
    

    Even if you create your components using Component Creator you still have to do this kind of stuff manually.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件
  • ¥150 求 《小魔指》街机游戏机整合模拟软件
  • ¥20 你好,我想问下easyExcel下拉多选,或者复选框可以实现吗
  • ¥20 双非跨考工科哪个专业和方向就业前景好?