mercredi 1 juillet 2015

Database Query into Associative Array using PHP

I am trying to grab data from my database and place in a format so I can call field1 and return field2.

In my mind I think this:

while($row = mysqli_fetch_assoc($result)) {
    $aa = $row["field1"];
    $bb = $row["field2"];
}

$cc = array(“$aa”=>”$bb”);

Will compute this:

$cc = array(
    "Row1a"=>"Stuff in field2 row1b",
    "Row2a"=>"Stuff in field2 Row2b",
    "Row3a"=>"Stuff in field2 Row3b",
    "Row4a"=>"Stuff in field2 Row4b",
    );

After this I will be able to:

echo $cc('Row1a');

To display:

Stuff in field2 row1b

Aucun commentaire:

Enregistrer un commentaire