phpnewbie112 Posted April 9, 2008 Share Posted April 9, 2008 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 More sharing options...
zenag Posted April 9, 2008 Share Posted April 9, 2008 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> } Link to comment https://forums.phpfreaks.com/topic/100285-del-bottom-with-query-listing/#findComment-512796 Share on other sites More sharing options...
zenag Posted April 9, 2008 Share Posted April 9, 2008 put semicolon after $sql=mysql_query("select * from tablename"); Link to comment https://forums.phpfreaks.com/topic/100285-del-bottom-with-query-listing/#findComment-512804 Share on other sites More sharing options...
phpnewbie112 Posted April 9, 2008 Author Share Posted April 9, 2008 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 Link to comment https://forums.phpfreaks.com/topic/100285-del-bottom-with-query-listing/#findComment-513228 Share on other sites More sharing options...
zenag Posted April 10, 2008 Share Posted April 10, 2008 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> Link to comment https://forums.phpfreaks.com/topic/100285-del-bottom-with-query-listing/#findComment-513591 Share on other sites More sharing options...
phpnewbie112 Posted April 11, 2008 Author Share Posted April 11, 2008 Hello, thank you but I tried it and it is not working properly. it is still showing only the last record in the textbox rather then the selected one.... any ideas? Link to comment https://forums.phpfreaks.com/topic/100285-del-bottom-with-query-listing/#findComment-514772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.