php - 选择多行并连接成一个 - 在 joomla

标签 php mysql joomla

我在选择多行并将它们作为一行检索时遇到问题。问题在于 Joomla 将用户配置文件中的数据存储在名为 profile_key 和 profile_value 的两列中。我想从名为“profile.li_vid”的“profile_key”列中检索所有行,“profile.li_kre”对应于列“profile_value”,其中值为“1”。

数据库草稿

user_id | profile_key        | profile_value
475     | profile.li_vid     | "1"
475     | profile.li_kre     | "1"
475     | profile.address1   | "1"
476     | profile.li_vid     | "1"
476     | profile.li_kre     | "1"
476     | profile.address1   | "1"

代码

  $db = JFactory::getDbo(); 
    $query = $db->getQuery(true);
    $query
        ->select ($db->quoteName(array('a.id','a.name', 'b.profile_value','b.profile_key')))
        ->from ($db->quoteName('#__users','a'))
        ->where ($db->quoteName('b.profile_key') . " = " . $db->quote('profile.li%'))

        // ->where ($db->quote('profile_value') . " = \"1\" " )
        ->join('INNER', $db->quoteName('#__user_profiles','b').'ON('.$db->quoteName('a.id').'='.$db->quoteName('b.user_id').')')
        ->order($db->quoteName('a.name').'ASC')
     ;
    $db->setQuery($query);
    $rows = $db->loadObjectList();

当我在 foreach 循环中将它们回显到屏幕上时,它们出现在我的表中的不同行中,因为代码逐行循环遍历每个查询结果。我想到了一个解决方案,我将多行连接成一个 - 但是如何呢? 我希望你能帮助我。

最佳答案

请记住:默认情况下,GROUP_CONCAT() 的字符限制为 1024!

关于php - 选择多行并连接成一个 - 在 joomla,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30573718/

相关文章:

php - SQL LEFT JOIN 问题 - 结果错误

php - Virtuemart 2/Joomla 2.5.4 浏览页面上的 Virtuemart 添加到购物车按钮

即使在 php5 fpm .ini 文件中禁用,Linux 魔术引号仍然存在

javascript - FIrebug 中不包含文件且为空的脚本元素

javascript - 意外的 JSON 行为

javascript - 来自数据库的 PHP 验证

mysql - 如何在sql中对行进行分组排序

php - 具有多个 where 语句的多个选择查询

c# - 如何通过命令行在远程机器上触发批处理文件

joomla - 从 1.5 升级到 2.5 后,文章内容未显示在 joomla 2.5 中