Tudor Manole Tudor Manole - 1 year ago 72
PHP Question

Duplicate results from MySQL table?

I have the following code:


$select = mysqli_query ($con,"SELECT field_2 FROM info4");
if (! $select) {
die('Query unfunctional ' . mysqli_error($con));

<td><select name="City">

while ($res=mysqli_fetch_array($select)){
foreach($res as $value){
echo "<option>" . $value . "</option>";

is the connection.

But this outputs the dropdown with all of the values duplicated. For example if I had 1 and 2 in my table, it outputs: 1/1/2/2 (in the dropdown). I'm supposing I'm making a mistake in my code--can anyone see it by any chance?

Thanks in advance.

Answer Source

try this. foreach loop in this case is unneccessary.

while ($res=mysqli_fetch_assoc($select)){
echo "<option>" . $res["field_2"] . "</option>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download