How to show tables from a database i checked?


How to show tables from a database i checked?



Hellow guys. How to show tables from a database I checked when I submit? I'm not sure with my codes. this code will just display the list of a database with a checkbox, I want when I checked it, it shows the table of the database I check. please help


<?php
$link = mysqli_connect('localhost','root','');

$sql = "SHOW databases";
$result = mysqli_query($link, $sql);

while ($row = mysqli_fetch_row($result)) {
$table = $row[0]."<br>";
?>
<form action="" method="post">
<input type="checkbox" name="database" value="<?php echo $table;?>">
<?php echo $table?>
<?php
}
?>
<input type="submit" name="submit">
</form>



I almost got it. My new problem is this. How to place the value of echo to complete the query. or im just doing it wrong..


<?php
if (isset($_POST['database'])){

echo $_POST['database'];

$qry = "show tables from ";
$res = mysqli_query($link,$qry);

while ($row = mysqli_fetch_array($res)){
echo $row[0]."<br>";
}
}





Possible duplicate of Displaying all table names in php from MySQL database
– Mike
Jun 29 at 10:31





@Mike from a database i checked...
– Newbee
Jun 29 at 10:34




2 Answers
2



I think your query is wrong.
Let say your dbname is 'mydb' then query should be...
"show tables from mydb".





I already know that sir, what I want is when I checked it.
– Newbee
Jun 29 at 10:51


<?php
$link = mysqli_connect('localhost','root','');

$sql = "SHOW databases";
$result = mysqli_query($link, $sql);

while ($row = mysqli_fetch_row($result)) {
$table = $row[0];
?>
<form action = "" method = "post">
<input type = "checkbox" name = "database" value = "<?php echo $table;?>"> <?php
echo $table?>
<?php
}
?>
<input type = "submit" name = "submit">
</form>
<?php
if (isset($_POST['database'])){

$qry = "show tables from ".$_POST['database'];
$res = mysqli_query($link,$qry);


while ($row = mysqli_fetch_array($res)){
echo $row[0]."<br>";
}
}
?>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV