【问题标题】:Joomla query with multiple where具有多个位置的 Joomla 查询
【发布时间】:2015-06-12 11:25:08
【问题描述】:

我正在尝试从数据库中获取结果,但我的 sql 不是很好。

我在 joomla3 上,我想要实现的是拥有来自多个类别的文章列表,我想按日期(而不是按类别)对所有文章的结果进行排序,但“where”子句似乎没有工作。

这些查询到目前为止我已经尝试过,但没有人在工作:

$query->select('id, title, introtext, created, created_by, images, urls');
$query->from('#__content');

//1st 'where' try
$query->where('catid=12'OR' catid=11'OR' catid=10');

//2nd 'where' try
$query->where('catid=12');
$query->OR('catid=11');
$query->OR('catid=10');

//3rd 'where' try
$query->where('catid = 11', 'OR')
->where('catid = 12');

$query->order('id DESC');

关于我做错了什么的任何建议? 谢谢

【问题讨论】:

    标签: php mysql sql joomla


    【解决方案1】:

    在你的 Joomla 格式的查询中试试这个

    $query->select('id, title, introtext, created, created_by, images, urls'); 
    $query->from('#__content');
    $query->where('catid IN (10, 11, 12)'); //quotes fixed
    $query->order('id DESC'); 
    
    $db->setQuery($query);
    

    【讨论】:

    • 您好,感谢您的回答,并对我的代码中的混乱感到抱歉,我现在已经对其进行了编辑。我试过这段代码,但它不起作用: $query->select('id, title, introtext, created, created_by, images, urls'); $query->from('#__content'); $query->where catid IN ( 10, 11, 12 ); $query->order('id DESC'); $db->setQuery($query);
    • 我们是否在$query->where catid IN ( 10, 11, 12 ); 上缺少单引号在执行$db->setQuery($query); 之前我们可以在浏览器中打印查询
    • 我试过这个:$query->where catid IN ('10','11','12');还有这个: $query->where catid IN (' 10, 11, 12 ');但它说两者都有语法错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2020-08-12
    • 1970-01-01
    • 2013-03-16
    相关资源
    最近更新 更多