2

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
5
  • What is the probelm? Commented Sep 4, 2016 at 15:59
  • 1
    You are missing the closing quote in the value attribute. value=-->"<--'.$name.'-->??<-- Commented Sep 4, 2016 at 16:00
  • See screenshot, only every other table is being returned on the dropdown Commented Sep 4, 2016 at 16:01
  • @Dekel has the answer, thank you. That makes complete sense now Commented Sep 4, 2016 at 16:03
  • You are welcome. Next time just look at your html (the output), it will be much easier to find the problem (you can use view-source or inspect element for that). Commented Sep 4, 2016 at 16:05

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.