[英]Array to string conversion error in Radio
$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>';
}
I am getting an error on the Radio line .我在无线电线路上收到错误消息。
Array to string conversion
But when I print_r the array, the values are perfectly fetched and assigned in the array.但是当我 print_r 数组时,这些值被完美地提取并分配到数组中。 What is the problem?
问题是什么?
Problem is you are casting the id $row['id']
to an array before assigning it to the $array
variable replace问题是您在将 id
$row['id']
分配给$array
变量替换之前将其转换为数组
$db_id = $rows['id'];
$array[] = array($db_id); //casting the value to an array here
with和
$array[] = $rows['id'];
Should alleviate the issue.应该可以缓解问题。 I guess to be more clear, you're not really casting, rather assigning a new array with the value of
$row['id']
as its only value, none the less that is the issue.我想更清楚一点,您并没有真正进行强制转换,而是分配了一个新数组,其唯一值是
$row['id']
,但这仍然是问题所在。
Copy and paste following code :复制并粘贴以下代码:
$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>';
}
As Lashane mentioned to assign, a value on the array you need to use this syntax:正如 Lashane 提到的要分配的,数组上的值需要使用以下语法:
$array[] = $db_id;
http://www.php.net/manual/en/language.types.array.php http://www.php.net/manual/en/language.types.array.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.