I am newbabie in PHP. I want to get table name from MYSQL, put that name to combobox. When I select combobox I will get the selected name to select query and print the table I chose.
For example: In mysql I have some table: book_economy, book_techology, book_magazine and some table a,b,c,d...
I only want to get 3 table (book_economy, book_techology, book_magazine) into combobox.
And then, when I chose book_economy I will put this name to SQL select query "*Select * from book_economy....*" and print information of this table.
Now I can filter these table, but I have problem to put these value to combobox and get selected value. Please help me, thank you.
Here is my code
<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
?>
$db= mysql_connect("localhost","root","");
if(!$db)
{
echo "CAN'T CONNECT DATABASE";
exit;
}
$table= mysql_query("show tables from data2 LIKE '%book_%'");
echo "<select name = 'venue' >";
while (($row = mysql_fetch_row($table)) != null)
{
echo "<option value = '{$row['0']}'";
if ($selected_venue_id == $row['0'])
echo "selected = 'selected'";
echo ">{$row['0']}</option>";
}
echo "</select>";
It will be much better to create only one table, and add column "category", where you write category for each record, then when you want to get categories you wrote:
SELECT DISTINCT Category FROM Book;
To list only books from category use:
SELECT * FROM Book WHERE Category = 'CATEGORY';
Or even better to create separate table "Categories" with id and name, then only put category_id in Book table.