Get rows from mysql table to php arrays

前端 未结 5 2044
借酒劲吻你
借酒劲吻你 2021-02-04 10:10

How can i get every row of a mysql table and put it in a php array? Do i need a multidimensional array for this? The purpose of all this is to display some points on a google ma

5条回答
  •  抹茶落季
    2021-02-04 10:34

    $sql = "SELECT field1, field2, field3, .... FROM sometable";
    $result = mysql_query($sql) or die(mysql_error());
    
    $array = array();
    
    while($row = mysql_fetch_assoc($result)) {
       $array[] = $row;
    }
    
    echo $array[1]['field2']; // display field2 value from 2nd row of result set.
    

提交回复
热议问题