Array erzeugen

qsrs

Erfahrenes Mitglied
Hallo zusammen,

ich benötige Hilfe mit einem Array. Folgende Struktur eines Array möchte ich mittels MySQL-Abfrage dynamisch erzeugen:

PHP:
$address = array(
		"1" => array("Address" => "Bandra, Mumbai, India" , "Name" => "Bandra"),
		"2" => array("Address" => "Khar, Mumbai, India" , "Name" => "Khar"),
		"3" => array("Address" => "Santacruz, Mumbai, India" , "Name" => "Santacruz"),
		"4" => array("Address" => "Andheri, Mumbai, India" , "Name" => "Andheri"),
		"5" => array("Address" => "Jogeshwari, Mumbai, India" , "Name" => "Jogeshwari"),
		"6" => array("Address" => "Goregaon, Mumbai, India" , "Name" => "Goregaon"),
		"7" => array("Address" => "Malad, Mumbai, India" , "Name" => "Malad"),
		"8" => array("Address" => "Kandivili, Mumbai, India" , "Name" => "Kandivili"),
		"9" => array("Address" => "Borivali, Mumbai, India" , "Name" => "Borivali"),
		"10" => array("Address" => "Dahisar, Mumbai, India" , "Name" => "Dahisar"),
		"11" => array("Address" => "Mira Road, Mumbai, India" , "Name" => "Mira Road"),
		"12" => array("Address" => "Bhayander, Mumbai, India" , "Name" => "Bhayander"),
		"13" => array("Address" => "Naigaon, Mumbai, India" , "Name" => "Naigaon"),
		"14" => array("Address" => "Vasai, Mumbai, India" , "Name" => "Vasai"),
		"15" => array("Address" => "Nallasopara, Mumbai, India" , "Name" => "Nallasopara"),
		"16" => array("Address" => "Virar, Mumbai, India" , "Name" => "Virar"),
		"17" => array("Address" => "Churchgate, Mumbai, India" , "Name" => "Churchgate"),
		"18" => array("Address" => "Charni Road, Mumbai, India" , "Name" => "Charni Road"),
		"18" => array("Address" => "Grant Road, Mumbai, India" , "Name" => "Grant Road"),
		"19" => array("Address" => "Dadar, Mumbai, India" , "Name" => "Dadar"),
		"20" => array("Address" => "Mahim, Mumbai, India" , "Name" => "Mahim"),
		"21" => array("Address" => "King Circle, Mumbai, India" , "Name" => "King Circle"),
		"22" => array("Address" => "Worli, Mumbai, India" , "Name" => "Worli"),
		);

Meine SQL-Abfrage sieht so aus:


Code:
$sql = "SELECT * FROM `$dbtable8`";
$query = mysql_query ($sql);
$array = mysql_fetch_array ($query);

In der Tabelle sind dann die Spalten 'user_city' und 'user_street', welche dann in dem Array stehen müssten. Wie kann ich am besten das Array dynamisch erzeugen? Vielen Dank für eure Hilfe.
 
Zum Beispiel so:
PHP:
$sql = "SELECT user_city, user_street FROM `$dbtable8`";
$query = mysql_query ($sql) or die('ERROR!');

$result = array();

while ($row=mysql_fetch_array($query, MYSQL_ASSOC))
{
  $result[] = array(
    'Address' => $row['user_city'],
    'Name' => $row['user_street']
  );
}
 
Zurück