Jump to content

DEL bottom with query listing


phpnewbie112

Recommended Posts

Hello, could you pls advice how to add a delete bottom near every listing from a simple "select query". for example

 

Search Result

___________

 

 

Name Age Status

X      18  on  [del]

Y      19  on  [del]

Z      20  on  [del]

 

if I click on the 2nd one, it should delete the 2nd record.

 

Thanks a million

Link to comment
https://forums.phpfreaks.com/topic/100285-del-bottom-with-query-listing/
Share on other sites

try this.........

 

$id=$_GET["id"];

if($_GET["id"])

{

$sqlquery=mysql_query("delete from tablename where id='$id'");

}

 

 

 

Name Age Status

X      18  on  [del]

Y      19  on  [del]

Z      20  on  [del]

$sql=mysql_query("select * from tablename")

while($result=mysql_fetch_array($sql))

{

echo $result["Name"];

echo $result["Age"];

echo $result["Status"];

<a href="?id=<? echo $result["id"];?>">delete</a>

}

thanks for the answer  I will check it and get back to you meanwhile I have another question if you don't mind. with the same structure assume I added near [del] a checkbox so that if I click the checkbox the value of the  Name appear in a seperate textbox by using:

 

<script type="text/javascript" language="javascript"><!--

 

function ChgText()

{

  var MyElement = document.getElementById("newtextbox");

  MyElement.value = "<?php

 

 

Print "".$date['name'] . "";

 

?>

 

I have test it but I am always having the LAST record showing only and NOT from the selected row

if u need single textbox do it as it is....

<html>
<head>
<script type="text/javascript">
function valid(val)
{

if(document.getElementById("check").checked==true)
{
//alert(val);
document.getElementById('val').innerHTML= val;
}

}
</script>
<script type="text/javascript">

//function ChgText()
//{alert('ass');
//   //var MyElement = document.getElementById("newtextbox");
//   //MyElement.value = "<?php Print "".$date['name'] . "";?>
//}
</script></head><body>
<? if($id)
{
$sqlquery=mysql_query("delete from tablename where user_id='$id'");
}
$sql=mysql_query("select * from tablename");
while($result=mysql_fetch_array($sql))
{
echo $result["name"];
echo $result["age"];

?>
<!--<input type="button" name="sub" value="submit" onClick="valid()">-->
<input type="checkbox"  id="check" name="check" value="<? echo $result["name"];?>"   onClick="valid(this.value)">
<a href="?id=<? echo $result["user_id"];?>">delete</a>
<?
}
?>
<div id="val"></div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.