Jump to content

Recommended Posts

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

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?

Regards
Huggie
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 variable
echo "Deleted records!";
}
[/code]
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 76

have i missed anything out from yur code...?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.