Some code here, I want store mysql query result into an array with php, but my code return result: 2h
, not what I wish.(the correct result should be 36,35,34,33
Use mysql_fetch_assoc instead of mysql_fetch_array
http://php.net/manual/en/function.mysql-fetch-assoc.php
I think you wanted to do this:
while( $row = mysql_fetch_assoc( $result)){
$new_array[] = $row; // Inside while loop
}
Or maybe store id as key too
$new_array[ $row['id']] = $row;
Using the second ways you would be able to address rows directly by their id, such as: $new_array[ 5]
.
What about this:
while ($row = mysql_fetch_array($result))
{
$new_array[$row['id']]['id'] = $row['id'];
$new_array[$row['id']]['link'] = $row['link'];
}
To retrieve link and id:
foreach($new_array as $array)
{
echo $array['id'].'<br />';
echo $array['link'].'<br />';
}