2014-04-24 48 views
-1
$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE user_id = '".$id."' "); 
while($rows = mysql_fetch_assoc($data)) 
{ 
$db_id = $rows['id']; 
$array[] = array($db_id); 
} 

foreach($array as $value) 
{ 
echo '<input type="radio" name="change" value="'.$value.'"><br>'; 
} 

我在無線電行上收到錯誤。收音機中的陣列到字符串轉換錯誤

Array to string conversion 

但是,當我print_r數組,值完美取得和分配在數組中。 問題是什麼?

+3

取代'$陣列[] =陣列($ DB_ID);'與' $ array [] = $ db_id;' –

+1

thnks !!發佈它作爲答案! :) – user3545779

回答

0

複製和粘貼下面的代碼:

$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE user_id='$id'"); 
    while($rows = mysql_fetch_assoc($data)) 
    { 
    $array[] = $rows['id']; 
    } 

    foreach($array as $value) 
    { 
     echo '<input type="radio" name="change" value="'.$value.'"><br>'; 
    } 
1

問題是你是鑄造的ID $row['id']到一個數組它分配給$array變量之前頂替

$db_id = $rows['id']; 
$array[] = array($db_id); //casting the value to an array here 

$array[] = $rows['id']; 

應該緩解這個問題。我想更清楚的是,你並不是真的在投射,而是將一個新陣列的值設爲$row['id']作爲唯一值,但問題不在此列。