douxingmou4533 2015-11-09 03:01
浏览 20
已采纳

从数据库中选择所有管理员并放入数组[关闭]

I have a table in my database called dragonStaff with the following fields admins moderators tester I am trying to select the admins with this code and put them in the array $admin_array

    $result = mysql_query("SELECT * FROM dragonStaff") or   die(mysql_error());
    while($row = mysql_fetch_array(   $result )){
    $admins = $row['admins'];
     }
    $admin_array = implode(",",    $admins);

The point of this is so I can create content only certain people with permissions can access which i use this code(hint name is predefined in an include file)

    <? if(in_array($name,$admin_array)){?>
    //content
    <?}?>

I have added my name to the database for admin but the content is not displaying I have no clue what im doing wrong

  • 写回答

1条回答 默认 最新

  • dongyingjiu0669 2015-11-09 03:08
    关注

    Try the simple approach:

    $result = mysql_query("SELECT * FROM dragonStaff") or   die(mysql_error());
    $admin_array = array();
    while($row = mysql_fetch_array(   $result )){
        $admin_array[] = $row['admins'];
    }
    print_r($admin_array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line