0
The title is already self-explanatory. I’ve tried everything, but I feel like everything I’ve done is completely wrong, haha. If anyone can help me, I need to dropdown where the values to be selected will be table names from my database. Thank you.
[EDIT] The easiest way I see is to pull all tables through the function mysqli_list_tables and then I would use a while, or I would print this in the dropdown. The point is that even this simple function below is not working. I tried to leave only the fundamental part (the function of listing tables) for testing purposes and even then, nothing works. (Even, in my index file, after calling the function dropdownAnos() nothing else works).
function dropdownAnos () {
$host = "localhost";
$user = "root";
$pass = "root";
$banco = "teste";
mysqli_connect($host, $user, $pass);
$tabelas = mysqli_list_tables($banco);
print_r($tabelas);
}
I’ve changed this code over and over again, I’ve tried every possible way and this is the simplest version I could get. Even so, it doesn’t work. (I’m glad I saved it on github, otherwise I would have lost everything haha).
[EDIT FINAL] I did it, guys. I’ll post the answer in case someone falls for this topic:
function dropdownAnos () {
$str = "";
$db = new mysqli('localhost', 'root', 'root', 'teste');
$teste = $db->query('SHOW TABLES');
while ($t = $teste->fetch_array()) {
$str = $str . "<option>" . $t[0] . "</option><br>";
}
echo $str;
}
Thank you to everyone who helped.
@Michael please post what you did!
– novic
Make a tour by stackoverflow, learn a little about the rules and good practices. Then edit your question and enter the code of what you’ve tried...
– Marco Giovanni
The title is not self-explanatory in itself, we need the code in order to help you. It’s hard to know what you need if you don’t show us what you’re trying to do.
– Wallace Maxters
This function does not exist in the extension
MySQLi
only in the old.– rray
@rray then the way would be to make a query like "show Tables from $bank"? I’ve tried and it didn’t work
– Michael Sampietro
And you already tried to consult
select * from information_schema.tables
- Reference– Marco Giovanni
@Marcogiovanni already yes, but I must have done something wrong. I managed to do using "show Tables", posted the answer in the question, thank you.
– Michael Sampietro
@Michaelsampietro left the tab open here and had not updated hehe
– Marco Giovanni