开发者

how to delete a column from a mysql db when its displayed from a while loop in a jquery dialog with ajax

开发者 https://www.devze.com 2023-03-01 06:44 出处:网络
I have this code that is displayed in a jquery dialog .load()\'ed from a php script $sql = \' SELECT * FROM

I have this code that is displayed in a jquery dialog .load()'ed from a php script

$sql = '
    SELECT
        *
    FROM
        table
    WHERE
        id="'.$id.'"
';

$query = mysql_query($sql);
while($rows = mysql_fetch_array($query)) {
    echo "Category: <input type='text' name='category[]' value=".$rows['category']." />";
}

this is part of a form that is posted to an external script to insert/update the db. The problem开发者_开发知识库 im having is how can I delete that column onclick by adding an a href "delete" after the input to be echoed, effectively deleting it from the db?


while($rows = mysql_fetch_array($query)) {
    echo "Category: <input type='text' name='category[]' value=".$rows['category']." />";
    echo "<a href="UrlWhereCodeOfDleteToBEWrite?task=delete&cat=".$rows['category'].">Delete</a>";
}

In file the above link will redirect write as

if(isset($_GET['task']) && $_GET['task'] == 'delete'){
   if(!isset($_GET['cat'])){
      die('Invalid cat to delete');
   }  

   $sql = "DELETE FROM tableName WHERE columnName = '".$_GET['cat']."' ";
   mysql_query($sql); 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消