当前位置:Gxlcms > PHP教程 > ,取值输出问题

,取值输出问题

时间:2021-07-01 10:21:17 帮助过:7人阅读

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

输出结果是: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;      }   }

这个类是从网上找的

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

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')");

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


试试。

人气教程排行