almightyegg Posted November 22, 2006 Share Posted November 22, 2006 i have a loop of messages and each has a check box next to it. If the user checks the box and presses delete I want the ones checked to delete but i hav no idea where to start...if anyone knows any good tutorials or wants tell help me out, please do :D thanks for reading :) Link to comment https://forums.phpfreaks.com/topic/28157-check-box-delete-resolved/ Share on other sites More sharing options...
HuggieBear Posted November 23, 2006 Share Posted November 23, 2006 Firstly, it would be a good idea if you posted your code, this would allow us to help you better, and secondly, try to explain things in a little more detail, as this description is a bit ambiguous... "I have a loop of messages".Do you mean that you're pulling results from a database and using a loop to output them all? Then you want the checkbox that's output next to them to delete the record from the database?RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/28157-check-box-delete-resolved/#findComment-129041 Share on other sites More sharing options...
JasonLewis Posted November 23, 2006 Share Posted November 23, 2006 if you are going by what huggie said, and i think that is correct. from the sounds of the awesome (:P) description. no offence, but please be a bit more detailed...something like this?[code=php:0]//connect to db etc etc around here....$query = mysql_query("SELECT * FROM `table`");while($r = mysql_fetch_array($query)){echo $r['title']." - <input type='checkbox' name='select[]' value='".$r['id']."'><br>"; //just print a title and a text box. note the [], this creates an array of all selected checkboxes.}[/code]now if you have a form etc that goes to a page called delete.php or something have this somehwere after you have connected.[code=php:0]$selected = implode(",", $_POST['select']); //this would make the array into something like this 1,3,7,8 etc...if($selected == ''){echo "Nothing selected!";}else{mysql_query("DELETE FROM `table` WHERE `id` in ($selected)"); //deletes all from table if id is in variableecho "Deleted records!";}[/code] Link to comment https://forums.phpfreaks.com/topic/28157-check-box-delete-resolved/#findComment-129045 Share on other sites More sharing options...
almightyegg Posted November 23, 2006 Author Share Posted November 23, 2006 thanks but i have a problem with this bit:<input name='$select[]' value='".$posmes['id']."' type='checkbox'>it comes up with error:Parse error: syntax error, unexpected ']', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/lordofth/public_html/im/index.php on line 76have i missed anything out from yur code...? Link to comment https://forums.phpfreaks.com/topic/28157-check-box-delete-resolved/#findComment-129204 Share on other sites More sharing options...
almightyegg Posted November 23, 2006 Author Share Posted November 23, 2006 dont worry...solved it ;) Link to comment https://forums.phpfreaks.com/topic/28157-check-box-delete-resolved/#findComment-129260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.