PHP code to retrieve column data with dropdown menu

I am seeking a PHP code to fetch and retrieve data from a single column from a mysql table and display in a tabular form on the page. So I need a dropdown option list for the column names so every time a different column is selected, the relevant data is displayed on the page. Can someone provide me a code snippet or help me out with this, please? thanks.

I inserted an example image to show how it’d look. But it my case, i just need to display one column instead of multiple columns.


Hi,

I would query the database table for column names - it should be fairy simple,(google ).
Then use the column names as values in ,select, tag.

I am not sure if you can get what you want just by selecting a column name from dropdown option list, perhaps a submit button need adding.

Upon clicking on ,submit, the code then should grab $_POST for that dropdown list (select tag), feed the value from $_POST to query which should be built to retrieve data only for that column.

Need an AJAX call to a page that will process and return the new options, using the onchange event.

thanks, guys. I tried your suggestions already actually. but I couldn’t make it work, so trashed it. So I was hoping to get a code snippet here. I googled a lot but couldn’t find something like that. so decided to ask experts. thanks for your suggestions.

So, what did you try?

Basically I tried to modify this code here http://www.itgeared.com/articles/1403-ajax-php-sql-database-data-tutorial/ but I couldn’t achieve it. It is no exactly what I want, but structurally similar to it.

That is bad and outdated code anyway.

I would recommend creating an API, but that is me. What you basically need is two files.

  1. The actual file the actual form uses to display
  2. A background file that you can for updates.

http://test.andrewstonecipher.info/

yes, the code is outdated, but it works. Your example is similar to it.

Sponsor our Newsletter | Privacy Policy | Terms of Service