php - 从数据库中获取并分离单列数据

标签 php mysql

我试图在仪表板中仅显示用户选择的页面

我在数据库中有两列,如下所示

create table users(userid varchar(50), scripts varchar(100))

userid column我将拥有登录的用户名和 scripts column ,他们想要在仪表板中以逗号分隔格式显示的页面名称。 例如:总计、cust_orders...

我想从脚本列中单独获取页面名称,例如 total.php, cust_orders.php... 我尝试这样做

$sql = "select scripts from users where userid = '".$_SESSION['UserID']."' ";

$result = DB_query($sql,$db);
$myrow = DB_fetch_array($result);


foreach ($myrow as $res)
    {

        $array123[] = $res;
        $var123 = $array123[0];
        $var222 = $array123[1];

    }

但是它不会工作,因为页面可以从 1 到 8,有人可以帮我吗?

已编辑

我就是这样做的

$result = DB_query($sql,$db);
$myrow = DB_fetch_array($result);

$arr= $myrow['scripts'];

$arr1 = explode(',', $myrow['scripts']);
print_r ($arr1);

它成功了,它显示如下

Array ( [0] => total_dashboard [1] => customer_orders [2] => unpaid_invoice [3] => lat

但我如何动态地将它分开,我必须添加 .php对此...

最佳答案

$sql = "select scripts from users where userid = '".$_SESSION['UserID']."' ";
$result = mysql_query($sql,$db);
while($myrow = mysql_fetch_array($result))
{
    $arr=explode(',',$myrow["scripts"]);//this will strip the , separated values in an array 
    //now you can fetch the scripts from database
}

关于php - 从数据库中获取并分离单列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18465464/

相关文章:

php - 通过 cookie 在 php 和 node.js 之间安全地共享数据

php - Paypal IPN 响应适用于 Paypal 但不适用于 sandbox-Paypal?

php - 从动态创建的字段中获取值并通过 Ajax 将它们发送到 PHP

mysql更新一个字段加1

java - nameParameterjdbcTemplate 给出空指针异常

php - 像 SO 那样将数字表示为缩短(13500 => 13.5k)?

php - UserCake 迁移 - 管理员帐户/密码未登录

php - 防止默认不工作 Jscript if(confirm){}else{prevent default}

mysql - 选择指定年份的新商品或返回商品

mysql - 我应该使用复合主键(聚集索引)还是代理键和辅助索引?