0

我的链接表中有一个链接和标题列表,我正在尝试使用 IN 子句返回它们,但查询永远不会返回超过一行,并且总是返回集合的最小行。

SELECT title, url 
FROM opsx_links 
WHERE linkid IN('61','60','10','24','15','20','30','47')

这应该返回所有 8 个链接,因为它们都存在,但它只返回第 10 项的信息。如果我从列表中删除第 10 项,它将只返回第 15 项,依此类推。

我失去它还是什么?

我用谷歌搜索了我的屁股,找不到遇到这个问题的人。

谢谢。

-V

好的,我的错误是 php 代码

public function getLinks ($data) {
   $query  = $this->db->Fetch ("SELECT title, url 
             FROM {$this->prefix}links WHERE linkid IN(" . $data . ")");
   $result = $this->db->FetchObject ($query);

   foreach ($result as $key => $value):

      $result->$key = $this->replace_strings ($value);

   endforeach;

   $this->db->Free ($query);

   return $result;
}

每个 jeron 都试过这个

$res = array();

while ($result = $this->db->FetchObject ($query)):

    $res['title'] = $result->title;
    $res['url']   = $result->url;

endwhile;

现在只返回第一行而不是最小行。

世界上有什么?

好的,经过多次试验和错误以及各位大师的帮助,这就是答案。

public function getLinks ($data) {
     $query  = $this->db->Fetch ("SELECT title, url 
               FROM {$this->prefix}links WHERE linkid IN(" . $data . ")");  
     $res = array ();
     while ($results = $this->db->FetchArray ($query)):
          $obj = new stdClass;
          $obj->title = $results['title'];
          $obj->url = $this->replace_strings($results['url']);
          $res[] = $obj;
     endwhile;

     $this->db->Free ($query);

     return (object)$res;
}

谢谢您的帮助。

4

1 回答 1

1

编辑:您只能从结果集中获得一个结果:

$result = $this->db->FetchObject ($query);

应该是这样的:

$my_results = array();
while ($result = $this->db->FetchObject ($query))
{
  // make a new / clone the object, add it to the array and do the processing
}
return $my_results;
于 2012-04-03T02:22:16.000 回答