SNS中往往有什么好友呀什么的uid ,但是有些需求就需要通过好友的uid拼写为一个串来做一些特殊的用法,比如构造sql:
开始拼类似in(1,2,3,4,5)里面的串:
$uidstr 的结果如下:
发现多一个,(逗号)
$uidstr = trim($uidstr , ',') ;
经过trim($uidstr,',');后echo $uidstr;如下:
放入下面的函数中:
CheckUserFollowInList的原型:
select * from userfollow where uid=1548940117 and followuid in (1584778420,1305619077,1305619077,1582003980,1584778420,1052833673,1052833673,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420)
开始拼类似in(1,2,3,4,5)里面的串:
for($j=0; $j<count($current['record']);$j++)
{
$uidstr .= $current['record'][$j]['uid'] . ',';
}
{
$uidstr .= $current['record'][$j]['uid'] . ',';
}
$uidstr 的结果如下:
1584778420,1305619077,1305619077,1582003980,1584778420,1052833673,1052833673,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,
发现多一个,(逗号)
$uidstr = trim($uidstr , ',') ;
经过trim($uidstr,',');后echo $uidstr;如下:
778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420,1584778420
放入下面的函数中:
$arr_follow_list = $obj_userfollow->CheckUserFollowInList($uid, $uidstr);
CheckUserFollowInList的原型:
public function CheckUserFollowInList($uid, $followuids) {
$sql = "select * from {$this->table_name} where uid={$uid} and followuid in ({$followuids})";
echo $sql;
$result = $this->objPdo->Select($sql);
if ($result)
{
$rs_array = $this->objPdo->FetchAll();
return $rs_array;
} else
{
return FALSE;
}
}
$sql = "select * from {$this->table_name} where uid={$uid} and followuid in ({$followuids})";
echo $sql;
$result = $this->objPdo->Select($sql);
if ($result)
{
$rs_array = $this->objPdo->FetchAll();
return $rs_array;
} else
{
return FALSE;
}
}
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1647/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2009-3-2 10:40
评论列表