instr()查询不起作用

时间:2011-10-24 14:56:07

标签: php mysql

$condition = '200,310'; //these are numbers of pages for news to be driven out of

while (list($key,$nesto) = each($pluginid))
{
 $getnm = $DB->query("SELECT articleid, categoryid FROM " . TABLE_PREFIX . "p".$nesto."_newy
                    WHERE lang = '$userlang'
                    AND settings > 0
                    **AND instr(categoryid, $condition)**
                    ORDER BY settings ASC, datecreated DESC");
$rows = $DB->get_num_rows($getnm);
}

instr无效。任何想法如何使这个工作? categoryid包含一个数字。

2 个答案:

答案 0 :(得分:2)

如果你想检查categoryid是否是$ condition中提供的那个,你必须切换参数的位置:

AND instr('$condition', categoryid) > 0

答案 1 :(得分:2)

尝试使用IN代替INSTRIN可以使用索引,并且可能比INSTR更快。

$DB->query("SELECT articleid, categoryid FROM " . TABLE_PREFIX . "p".$nesto."_newy
  WHERE lang = '$userlang'
  AND settings > 0
  AND categoryid IN ($condition)
  ORDER BY settings ASC, datecreated DESC");