I've searched a long time and didn't found correct answer for this question that i want to delete only one table from database. so i have this:
<?php
$database_name = "XXXXXX";
if (!$link = mysql_connect('XXXXXX', 'XXXXXX', 'XXXXXX')) {
die("Could not connect: " . mysql_error());
}
$sql = "SHOW TABLES FROM $database_name";
if($result = mysql_query($sql)){
while($row = mysql_fetch_row($result)){
$found_tables[]=$row[0];
}
}
else{
die("Error, could not list tables. MySQL Error: " . mysql_error());
}
foreach($found_tables as $table_name){
$sql = "DROP TABLE $database_name.$table_name";
if($result = mysql_query($sql)){
echo "Success - table $table_name deleted.";
}
else{
echo "Error deleting $table_name. MySQL Error: " . mysql_error() . "";
}
}
?>
it will list all tables from database and delete all of theme but i want to delete them one by one. something like this:
delete.php?item=ONE_OF_TABLE
drop table by querystring with table name or ...
First take a look on mysql function deprecated
Then your SQL-Syntax has to be edited by a WHERE table_name LIKE 'ONE_OF_TABLE'
or replace ONE_OF_TABLE by $_GET['item']
The code posted does exactly what you want - it drops tables one by one in a cycle. If you mean - "Show tables to end user, THAN drop them one by one" - you should print the result of SHOW TABLES query and expect some other user interaction.