2015-01-10 32 views
-3

如何将此变为mysqli?如何将mysql_fetch_assoc更改为mysqli

// add meta_key to the query 
$get_user_data = mysql_query("SELECT `meta_value`,`meta_key` FROM `table` WHERE `user_id` = $user_id", $link); 

// use _assoc instead of _array, we do not need the numerical indexes. 
while($row=mysql_fetch_assoc($get_user_data)){ 
    $userdata[$row['meta_key']] = $row['meta_value']; 
} 
+1

那你试试? – fejese

+0

您可以从手册开始 - http://php.net/manual/en/mysqli.summary.php。 – panther

回答

0

只需简单的修改,你必须在你的代码所做的:

// add meta_key to the query 
$get_user_data = mysqli_query($link,"SELECT `meta_value`,`meta_key` FROM `table` WHERE `user_id` = $user_id"); 

// use _assoc instead of _array, we don't need the numerical indexes. 
while($row=mysqli_fetch_assoc($get_user_data)) 
{ 
    $userdata[$row['meta_key']] = $row['meta_value']; 
} 
+0

如何获取我的数据? $用户数据[2]; wokrs但不是$ userdata ['fist_name']; – user3563887

+0

“while($ row = mysqli_fetch_array($ get_user_data,MYSQLI_ASSOC)”,使用这行代替“while($ row = mysqli_fetch_assoc($ get_user_data))” –