Caaguazu Caaguazu - 3 months ago 7
HTML Question

PHP HTML Dropdown Menu returning every other result

I'm trying to output the table names of a mysql database into a dropdown menu. Although I was somewhat successful I've encountered a strange problem and I'm not sure what's causing it. Any ideas would be much appreciated

The code

$query="show tables from internal";

$result=mysql_query($query);

$result_array = array();

while($row = mysql_fetch_assoc($result))
{
$result_array[] = $row['Tables_in_internal'];
}

echo'<select name="Tables">';
foreach($result_array as $name){
echo'<option value="'.$name.'>'.$name.'</option>';
}
echo'</select>';


What show up on the page

Screenshot

What the database has for tables

2016_08_27_18_10
2016_08_28_03_35
2016_08_29_03_12
2016_08_30_03_34
2016_08_31_03_49
2016_09_01_03_22
2016_09_02_03_45
2016_09_03_03_35
2016_09_04_03_10

Answer

The value attribute in your code has only an opening quote (you are missing the closing one).

Check this line:

echo'<option value=-->"<--'.$name.'-->???<-->'.$name.'</option>';

Next time it will be much easier to view the source of your code (or inspect the element), this way you can solve such issues much faster and yourself:

View source example:

enter image description here

Inspect Example:

enter image description here