数组下拉列表

时间:2016-05-19 20:46:51

标签: php

我有3张桌子:

//COMPANIES
company_id    company_name
1             APPLES
2             BANANAS
3             ORANGES
4             PEARS


// FOLDERS
folder_id    company_id    folder_name
1            1             GREEN
2            4             YELLOW


// USERS
user_id    user_group_id    user_name    user_company_access
1          1                MARK        1,2,4
2          1                PAUL        2,3
2          1                JAMES       4

我正在尝试创建一个下拉菜单,只显示user_company_access(序列化)中包含company_id的用户

例如,当select folder_id ='2'下拉列表必须显示MARK和PAUL

// FOLDER COMPANY
$folder_id = '4';

// EXAMPLE COMPANIES
$result = mysql_query (" SELECT * FROM users");
$row = mysql_fetch_array($result, MYSQL_BOTH);
$user_company_access = $row['user_company_access']; 
$bar = unserialize(base64_decode($user_company_access));


// DROPDOWN
<?php
    $query = mysql_query(" SELECT * FROM users WHERE (folder_company_id IN (".implode(',',$bar).") ");

    if(mysql_error()){
        print(mysql_error());
    }

    echo'<select id="dropdown1" name="user_id" data-placeholder="[Select User]" class="select" style="width:100%;">';

    echo'<option value=""></option>'; {

        while($row = mysql_fetch_array($query))

        echo'<option value="'.$row['user_id'].'">'.$row['user_name'].' </option>';

    }
    echo'</select>';
    ?>

0 个答案:

没有答案