Suche PHP / MYSQL Hilfe

07/21/2015 13:15 Givemoney#1
Guten Tag,
ich möchte meine Datenbank ausgabe in einem Dropdown menü machen, das ganze Funktioniert auch soweit, bloß macht er jedesmal ein neues Dropdown menü anstatt eins.
Bild:

Kann mir jemand sagen, wie ich das ganze richtig anspreche.

Code:
PHP Code:
<!DOCTYPE html>
<html>
<head>

</head>
<body>


<?php
$q 
= ($_GET['q']);

$con mysqli_connect('localhost:3307','root','1234','justin');
if (!
$con) {
    die(
'Could not connect: ' mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM adress WHERE lastname = '".$q."'";
$result mysqli_query($con,$sql);


while(
$row mysqli_fetch_array($result)) {


  echo 
'<select>';
  echo 
'<option value = ".$row["firstname"]. ">' .$row["firstname"] . " " .$row["lastname"];
  echo 
'</select>';

    }

mysqli_close($con);
?>
</body>
</html>
Mfg

Givemoney
07/21/2015 13:21 Syc#2
Wie sollen wir dir das ohne Code sagen?
Vermutlich ist aber einfach eine for / foreach falsch.
07/21/2015 13:27 ~ JWonderpig ~#3
PHP Code:
<select>
        <?php foreach... ?>
</select>
Wahrscheinlich hast du die Select-Tags mit in der Schleife
07/21/2015 13:28 Givemoney#4
Code:
PHP Code:
<!DOCTYPE html>
<html>
<head>

</head>
<body>


<?php
$q 
= ($_GET['q']);

$con mysqli_connect('localhost:3307','root','1234','justin');
if (!
$con) {
    die(
'Could not connect: ' mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM adress WHERE lastname = '".$q."'";
$result mysqli_query($con,$sql);


while(
$row mysqli_fetch_array($result)) {


  echo 
'<select>';
  echo 
'<option value = ".$row["firstname"]. ">' .$row["firstname"] . " " .$row["lastname"];
  echo 
'</select>';

    }

mysqli_close($con);
?>
</body>
</html>
07/21/2015 13:30 ~ JWonderpig ~#5
So funktioniert es.
PHP Code:
<!DOCTYPE html>
<html>
<head>

</head>
<body>


<?php
$q 
= ($_GET['q']);

$con mysqli_connect('localhost:3307','root','1234','jus tin');
if (!
$con) {
die(
'Could not connect: ' mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM adress WHERE lastname = '".$q."'";
$result mysqli_query($con,$sql);



echo 
'<select>';

while(
$row mysqli_fetch_array($result)) {

echo 
'<option value = ".$row["firstname"]. ">' .$row["firstname"] . " " .$row["lastname"];


}

echo 
'</select>';

mysqli_close($con);
?>
</body>
</html>
07/21/2015 13:32 Givemoney#6
@Jwonderpig danke, für deine Perfekte und Schnelle hilfe.
07/21/2015 21:50 snow#7
#closed (on request)