Hi guys As the title says it, I would like to have the ability to drop/delete table/s from MySql. Each field will be marked with 'X' And, when the user clicks on it, than it should be deleted from database. Any suggestion would be fine.
Yes, I already made a query that lists all results from tables so I need to create a script that deletes some of these results on demand
Please take a look at this block of code, it lists some 10 records from database in relation to their id <?php echo '<span class="left_headers">RECENT ARTICLES<hr/></span>'; $query="SELECT * FROM articles ORDER BY date DESC LIMIT 0,10"; $rt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($rt)){ echo " <li ><a href='articles/index2.php?id=$nt[id]'> $nt[title] </a> </li> "; }?> Code (markup):
You need to create an HTML form that, when submitted, runs a query with the ID of the row and then issues the DELETE query to MySQL. I can do this for you very quickly; send me a PM if you're interested.
It is pretty simple to solve it. If you don't mind you can pm me your DB structure I will code for you.
Dear eritrea1, As I guess you have a DB table(article) with fields id, title... you can use ajax to delete the article based in its id, here is the code first print your delete article link like this: echo "<li id=\"article".$nt[id]."\"><a onclick=\"remove_article(".$nt[id].")>".$nt[title]."<img src=\"cross.jpg\"></a></li>"; PHP: which you are printing in while loop then js in your html header and don't forget to remove mygreatesite.com with your domain or host url <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script> <script type="text/javascript"> var root = "http://mygreatesite.com"; function remove_article(id){ $.ajaxSetup({ type:"post", url: root+"/remove_article.php" }); $.ajax({ data: 'id='+id, success:function(response){ if(response == 'true'){ alert('article has been removed'); $('#article'+id).remove(); } else{ alert('Some php error: '+response); } } }); } </script> Code (markup): now mysql query in remove_article.php if($_POST['id']){ $query = "DELETE FROM `article` WHERE `id`='.$_POST['id'].'"; mysql_query($query) or die(mysql_error()); echo 'true';} PHP: