从嵌套数组中选择数据

时间:2014-02-06 20:51:11

标签: php mysql

我遇到了问题,我有这样的数据

$query = mysql_query("SELECT * FROM ticket");
while ($r = mysql_fetch_assoc($query)){
$data_workgroup=$r['workgroup'];
$explode= explode(",",$data_workgroup);
print_r($explode);

我得到了这个

Array ( [0] => Technical Support)
Array ( [0] => Marketing [1] => Network Engineer )
Array ( [0] => Technical Support )
Array ( [0] => Technical Support [1] => Network Engineer )

我需要从该数组中获取值,因此我只能显示Workgroup Value

的数据
SELECT * FROM ticket where workgroup = ValueOFArray[Network Engineer/Technical Support]
希望你能帮助我。对不起我无法发布图片。谢谢:))

1 个答案:

答案 0 :(得分:0)

$ explode只是一个多维数组,所以:

$query = "SELECT * FROM ticket where workgroup = '".explode[0][0]."';";

您将执行以下查询:

SELECT * FROM ticket where workgroup = 'Technical Support';

更多信息: http://php.net/manual/es/function.explode.php