|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
delete dynamic content w/checkboxes
Okay I have been having this problem for a while now, I have found a few things online to help, but I don't fully understand it, and can't get the results properly.
I want to be able to delete dynamic things with checkboxes (much like hotmail). For instance I have a news page, which dysplays everything ina while loop. Thus I can't really id the posts to be deleted on form submission. I have found a few things about using arrays to do this, unfortunatly I can't get the results I want, I jsut don't understand array's enough. I always end up with output like 'array' or something. Can anyone show me in a simple manner how to do this?
__________________
hey it's the CHARKING |
|
#2
|
|||
|
|||
|
Maybe a couple quick examples of using associative arrays may help... try these examples on your own and
maybe you will find your answer: Associative arrays are just like regular arrays... An example of arrays that hold property information: Regular array: $propInfo = array('564-987-3246', '1875', '6542', 'pending'); is equivalent to: $propInfo[0] = '564-987-3246'; $propInfo[1] = '1875'; $propInfo[2] = '6542'; $propInfo[3] = 'pending'; Associative array: $propInfo = array('apn'=>'564-987-3246', 'bldsqft'=>'1875', 'lotsqft'=>'6542', 'status'=>'pending'); is equivalent to: $propInfo['apn'] = '564-987-3246'; $propInfo['bldsqft'] = '1875'; $propInfo['lotsqft'] = '6542'; $propInfo['status'] = 'pending';
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
what I have
okay... I sort of understand all of that, I think. Maybe I missed your point. But, here is what I have:
PHP Code:
okay so here is what I get when I use print_r to see the array: PHP Code:
gives me: Array ( [what] => news [delete] => Array ( [0] => 33 ) [ckDeleteAll] => Delete Checked ) which is fine, jsut what I want... but now I don't know how to put this result into a MYSQL_QUERY to delete the post... I hope this isn't too basic and annoying, I jsut can't figure it out myself. |
|
#4
|
|||
|
|||
|
Try
PHP Code:
|
|
#5
|
|||
|
|||
|
found solution
thank you for that last code, although I had that already. But I did find this last night, for anyone else that was maybe having this problem... I had seen many solutions, but none worked for me... until this.
which I am currently having trouble with for some reason also... but this worked last night PHP Code:
Use that along with this form: <form action="index.php?page=news" method="post"> <input name="delete[]" type="checkbox" value="<?php echo $postId; ?>"> <input name="delete" type="submit" value="Delete Checked"> </form> and there yah go. Thansk for helping me out there. Thanks for breaking my cow lamp. |
|
#6
|
|||
|
|||
|
thecharking,
I'm glad you understand my code, and I'm glad you are working hard to figure out your own problem, however, I'm not sure you understand some things still... I may be missing something, but I'm wondering how you are deleting posts in any logical fashion when you can't be sure which postId you are deleting. You seem to be putting the postid into the value of the checkbox, but do you realize that the value attribute is not being accesed by your foreach loop? You are accesing a numerically indexed array in which would be numbered from 0 to whatever your highest number of generated checkboxes is. Another thing is that the code: PHP Code:
could be simplified to: PHP Code:
|
|
#7
|
|||
|
|||
|
Ahh... so, for instance, if I were to (with my current code) delete the first and last checkboxes... it wouldn't work.. because it is just a numerical deleteion not based upon the postId's? Is this what you are saying? At any rate, I will change my code when I get home, I am at school at the moment. Thank you for pointing this out (if I even got what you meant right... :S)
|
|
#8
|
|||
|
|||
|
thanks
Okay so I am home and put your code in the page and it works fine. I am still very new to php, and can do mostly basic things still. But it seems to work like that, there is something tat is foreign until you play with it a bit, and then it makes mroe sense as time goes on. I'm sure foreach will be easier to understand as I run into it more. At any rate, thanks again!
|
|
#9
|
|||
|
|||
|
No problem... just look at your database tables and your code and try to figure out why this code works.
Try to think of your postid as a numerical index in the back of some book. Hope this helps. |
|
#10
|
|||
|
|||
|
hi there. I am having trouble understanding why you cannot append the id to the item to be deleted.
If you looking to delete something on the fly, maybe try a javascript onclick to hand off the delete to a php function? is that what you are trying to do? or did I misunderstand the post?
__________________
-- Jason |
|
#11
|
|||
|
|||
|
Quote:
|
|
#12
|
|||
|
|||
|
ohh ok,..so he is looking more for a forum "delete thread" checkbox?
delete the main heading and all sub-headings and content in it. easy enough ![]() |
|
#13
|
|||
|
|||
|
I think he pretty much has all that down... it was just the implementation that was hanging him up.
|
|
#14
|
|||
|
|||
|
new question
okay so what would I use to do the opposite, such as instead of delete the entry, make a new entry, or update an entry? A foreach statement is all I can think of, just from the sound of it, but I know little of how they really work. If you could point to a tutorial or something, it would be much appreciated... the php reference manual tends to be sort of confusing sometimes about things like this... anyway, thanks for the help! The use deletable checkboxes has been very needed and applied!
|
|
#15
|
|||
|
|||
|
You can update a record using the same id that you are passing to the delete script.
Just pass the appropriate id to the update script and in your update sql statement reference the id that is passed to the script. |