如何在逗号分隔列中选择值

时间:2015-08-31 19:01:48

标签: sql

大家好,我的数据库名为" page"值是逗号分隔我如何检测我所需的值是否在那里?!

列页面中的

值为:info,start,main,footer,chart

$page = "main";
$userPerm = "4";

$sql = "SELECT * FROM perm WHERE page= '".$page."' AND userPerm = '".$userPerm."' ";
$result = $dp->sql_query($sql);
if($row = $dp->sql_fetchrow($result))
{
    return $userPerm;
}else {
    return '';
}

1 个答案:

答案 0 :(得分:0)

如果值不是强制性的或始终存在,则不能。但是,如果始终存在,则可以执行此操作:

$string = "Summer is almost done";
$tok = strtok($string, ",");
while ($tok !== false) {
    if ($tok == "summer") {
      do your thing
    }
}