dongxiusuo9881 2013-08-27 12:29
浏览 62
已采纳

从数据库中提取和分离单列数据

I am trying to display only user selected pages in dashboard

I have two columns in database like this

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

in userid column i will have the logged in user name and in scripts column, names of the pages which they want to display it in dashboard in comma separated format. ex: total, cust_orders,...

I want to fetch page name from scripts column separately like total.php, cust_orders.php... i tried doing like this

$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];

    }

but it wont work as the pages can be from 1 to 8, can somebody please help me in this?

EDITED

I have done like this

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

$arr= $myrow['scripts'];

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

and it worked, it displays like this

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

but dynamically how can i separate it and i have to add .php to this ...

  • 写回答

2条回答 默认 最新

  • dongtuo3795 2013-08-27 12:51
    关注
    $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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 优质github账号直接兑换rmb,感兴趣伙伴可以私信
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)