Home > Backend Development > PHP Tutorial > ,取值输出问题

,取值输出问题

WBOY
Release: 2016-06-20 12:45:27
Original
983 people have browsed it

$idss = '3,2,7,5';$re = $db->findall('select id,title from aaa where id in('.$idss.')');foreach($re as $list){   echo $list['id'].',';}
Copy after login

输出结果是:2,3,5,7
怎么才能让它按照$idss的顺序输出:3,2,7,5, 呢?谢谢!


回复讨论(解决方案)

echo 3,2,5,7;

$db->findall
这个方法默认是按id排序吧,如果是需要修改这个方法。

select id,title from aaa where id in('.$idss.')

需要贴出结果集,以供分析

$db->findall
这个方法默认是按id排序吧,如果是需要修改这个方法。


//数据库执行语句   function query($sql){      if(!empty($sql)){	     $this->sql = $sql;		 $result = mysql_query($this->sql,$this->link_id);		 if(!$result){            return false;		 }else{		    $this->result = $result;			return $this->result;		 }      }else{		 return false;      }	     }   //获取数据列表 @param string $sql 查询语句 @return array 二维数组   public function findall($sql){      $result = $this->query($sql);      if ($result!==false){         $arr = array ();         $row = mysql_fetch_assoc($result);         while ($row){            $arr [] = $row;            $row = mysql_fetch_assoc($result);         }         return $arr;      }else{         return false;      }   }
Copy after login

这个类是从网上找的

$re = $db->findall("select id,title from aaa where id in($idss) order by fiind_in_set(id, '$idsd')");
Copy after login
Copy after login

select id,title from aaa where id in('.$idss.')

需要贴出结果集,以供分析


数据库结构:

$idss = '3,2,7,5';
$re = $db->findall('select id,title from aaa where id in('.$idss.')');
给出一个如3,2,7,5这样的ID字符串,想它按照3,2,7,5这个顺序输出对应的title的值。

$re = $db->findall("select id,title from aaa where id in($idss) order by fiind_in_set(id, '$idsd')");
Copy after login
Copy after login

$re = $db->findall("select id,title from table where find_in_set(id, ".$idss.")");
Copy after login


试试。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template