Jump to content

mysqli_result to array


grege

Recommended Posts

Hey Guys,

So I have a zip code database with 40,000 some entries... and I am reading a query and returning it and need it to store it in array similar to this snippet of code .

 

$cities = array(
array('city'=>'New York', 'state'=>'NY', 'zip'=>'10001'),
array('city'=>'Los Angeles', 'state'=>'CA', 'zip'=>'90001'),
array('city'=>'Chicago', 'state'=>'IL', 'zip'=>'60601'),
array('city'=>'Houston', 'state'=>'TX', 'zip'=>'77001'),
array('city'=>'Phoenix', 'state'=>'AZ', 'zip'=>'85001'),
array('city'=>'Philadelphia', 'state'=>'PA', 'zip'=>'19019'),
array('city'=>'San Antonio', 'state'=>'TX', 'zip'=>'78201'),
array('city'=>'Dallas', 'state'=>'TX', 'zip'=>'75201'),
array('city'=>'San Diego', 'state'=>'CA', 'zip'=>'92101'),
array('city'=>'San Jose', 'state'=>'CA', 'zip'=>'95101'),
array('city'=>'Detroit', 'state'=>'MI', 'zip'=>'48201'),
array('city'=>'San Francisco', 'state'=>'CA', 'zip'=>'94101'),
array('city'=>'Jacksonville', 'state'=>'FL', 'zip'=>'32099'),
array('city'=>'Indianapolis', 'state'=>'IN', 'zip'=>'46201'),
array('city'=>'Austin', 'state'=>'TX', 'zip'=>'73301'),
array('city'=>'Columbus', 'state'=>'OH', 'zip'=>'43085'),
array('city'=>'Fort Worth', 'state'=>'TX', 'zip'=>'76101'),
array('city'=>'Charlotte', 'state'=>'NC', 'zip'=>'28201'),
array('city'=>'Memphis', 'state'=>'TN', 'zip'=>'37501'),
array('city'=>'Baltimore', 'state'=>'MD', 'zip'=>'21201'),
);

 

Here is the code I currently have... But it is not being stored into an array, it is just a mysqli_result object with the correct amount of num_rows, and fields.

 

$cities = $zip->getAllZipCityState();

 

  
function getAllZipCityState() {
    
    // Get ALL Zip / City / State
    $query = 'SELECT ' . $this->dbZip . ', ' . $this->dbCity . ', ' . $this->dbState . ' ';
    $query.= 'FROM ' . $this->dbTable . ' ';
    
//$qry = mysql_query($query,$this->db);
    $qry = $this->db->query($query);
if(!$qry){
	echo "MySql Error #".mysqli_errno($this->db).': '.mysqli_error($this->db).'<br>';
	die;
}
    //return mysqli_fetch_array($qry);
    return $qry;
  }

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/218806-mysqli_result-to-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.