I have multiple adresses in a database, for each row 1 departure 1 arrival.
I would like to add these in a "form/select"
I can display all of these with :
echo $arraydep[0].$arrayarr[0];
but
$adresses = array($arraydep[0], $arrayarr[0]);
or
$adresses = array_merge($arraydep[0], $arrayarr[0]);
or
$adresses[] = array($arraydep[0], $arrayarr[0]);
does not display all in my form, only the departure and the arrival for only 1 row
It would really nice if you could help me :)
Here is my complete code :
<?php
include "./cfg/db.php";
$sql = 'SELECT * FROM commandes WHERE phone="555-1234"';
$list = mysqli_query($base, $sql) or die("Erreur SQL !" . $sql . "<br />" . mysqli_error());
mysqli_query($base, $sql) or die("Erreur SQL !" . $sql . "<br />" . mysqli_error());
while ($data = mysqli_fetch_array($list))
{
$arraydep = array(
$data[depadresse]
);
$arrayarr = array(
$data[arradresse]
);
echo $arraydep[0] . $arrayarr[0]; // echo all adresses from database for this phone number (for testing)
$adresses = array(
$arraydep[0],
$arrayarr[0]
);
}
?>
<form action="test2.php" method="post">
<select name="test2">
<?php
foreach($adresses as $adresse)
{
?>
<option value="<?php
echo $adresses . "<br />"; ?>">
<?php
echo $adresse . "<br />"; // only echo 1 departure and 1 arrival for 1 row in the drowdown menu
}
?>
</option>
</select>
<input type="submit" value="Valider" />
</form>
Regards.
$data['depadresse']mysqli_error()requires a db connection here.