As Lashane mentioned to assign, a value on the array you need to use this syntax:
$array[] = $db_id;
Question
$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. What is the problem?
Solution 2
As Lashane mentioned to assign, a value on the array you need to use this syntax:
$array[] = $db_id;
OTHER TIPS
Problem is you are casting the id $row['id']
to an array before assigning it to the $array
variable replace
$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.
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>';
}