我试图在仪表板中仅显示用户选择的页面
我在数据库中有两列,如下所示
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/