从SELECT WHERE IN查询MySQL中提取值

时间:2012-06-03 20:42:03

标签: php mysql database

这是对minimize select queries on the same table Mysql的跟进。我没有得到关于如何提取以下查询返回的单个数组值的完整答案:

$result = mysqli_query("SELECT * FROM u_settings WHERE setting IN
 ('username', 'password','email','tag','active','version','time','warn','dis')");

如何从 $result 数组中提取任何我想要的值,因为会返回许多具有相同列的行?

2 个答案:

答案 0 :(得分:1)

$result = mysql_query("SELECT * FROM u_settings WHERE setting IN
 ('username', 'password','email','tag','active','version','time','warn','dis')");

while($row = mysql_fetch_assoc($result))
    $settings[$row['setting']] = $row['u_settings'];

print_r($settings);

答案 1 :(得分:1)

$result上使用mysql_fetch_assoc()mysql_fetch_array()

注意:我建议您升级到MySQLiPDO,而不是now deprecated mysql_ *函数。