General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 23rd, 2003, 01:35 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Send a message via AIM to thecharking
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

Reply With Quote
  #2  
Old August 23rd, 2003, 02:34 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
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.

Reply With Quote
  #3  
Old August 23rd, 2003, 07:20 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Send a message via AIM to thecharking
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:
<form action="index.php?page=news" method="post">
<?
PHP 

if (isset($_POST['delete'])) 
{

!
print_r($_POST); 

}

<
tr><td width="100%" bgcolor="#3A59A8"><center>News</center></td></tr>
<?
php
    
//some basic table that spits out the news...


<tr><td><table width="100%" border="0">
  <
tr
 <
td width="100%"><font size="2">
 
<?
php
$nPoster 
= @mysql_query("SELECT * FROM users WHERE userId ='" $nRow[2] . "'") or die(mysql_error());
while (
$nName mysql_fetch_row($nPoster))
 { 
//blah blah blah not of importance...    


 //the news is here
//and then other user info...

/but here is the code that I'm working with...

 <input type="hidden" name="what" value="news">
 
//this is a link to edit... of no importance really...

<a href="index.php?page=addnews&what=news&strMethod=edit&post=<?php echo $nRow[0]; ?>">Edit Post</a> ||

//this is the problem. I am looping through the results, and then
//each newsId is placed in an array.

<input name="delete[]" type="checkbox" value="<?php echo $postId; ?>">

//another basic link for deleting...
<a href="index.php?page=news&strMethod=deletepost&post=<?php echo $nRow[0]; ?>">Delete Post</a>

<input name="ckDeleteAll" type="submit" value="Delete Checked">
    </td>
  </tr></form>

//and the page closes out 


okay so here is what I get when I use print_r to see the array:

PHP Code:
if (isset($_POST['delete'])) 

!
print_r($_POST); } 


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.

Reply With Quote
  #4  
Old August 24th, 2003, 04:38 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
Try
PHP Code:
<input name="delete[<?php echo $postId; ?>]" type="checkbox" value="<?php echo $postId; ?>"

Reply With Quote
  #5  
Old August 24th, 2003, 10:59 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Send a message via AIM to thecharking
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:
if (isset($_POST['delete'])) 


foreach (
$_POST['delete'] as $value) { 
    
$query mysql_query('DELETE FROM news WHERE newsId = \'' $value '\';'); 
    unset(
$query); 
    }
 } 


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.

Reply With Quote
  #6  
Old August 25th, 2003, 01:27 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
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:
if (isset($_POST['delete'])) 


foreach (
$_POST['delete'] as $value) { 
    
$query mysql_query('DELETE FROM news WHERE newsId = '' . $value . '';'); 
    unset(
$query); 
    }
 } 

could be simplified to:
PHP Code:
if (isset($_POST['delete'])) 

  
$where join(','$_POST['delete']);
  
$query mysql_query("DELETE FROM news WHERE newsId IN ($where);"); 


Reply With Quote
  #7  
Old August 26th, 2003, 03:06 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Send a message via AIM to thecharking
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)

Reply With Quote
  #8  
Old August 26th, 2003, 07:29 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Send a message via AIM to thecharking
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!

Reply With Quote
  #9  
Old August 27th, 2003, 10:35 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
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.

Reply With Quote
  #10  
Old August 27th, 2003, 01:21 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 16
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

Reply With Quote
  #11  
Old August 27th, 2003, 02:18 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
Quote:
If you looking to delete something on the fly, maybe try a javascript onclick to hand off the delete to a php function?
That would only allow the user to delete one post at a time, sending the information to the server each and every time something is clicked.

Reply With Quote
  #12  
Old August 27th, 2003, 03:01 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 16
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

Reply With Quote
  #13  
Old August 27th, 2003, 11:11 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
I think he pretty much has all that down... it was just the implementation that was hanging him up.

Reply With Quote
  #14  
Old August 28th, 2003, 08:35 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Send a message via AIM to thecharking
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!

Reply With Quote
  #15  
Old August 28th, 2003, 09:42 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
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.

Reply With Quote
  #16  
Old August 29th, 2003, 04:08 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 16
yep thats how I do it heh

Reply With Quote
  #17  
Old August 30th, 2003, 03:33 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Send a message via AIM to thecharking
thanks

thanks guys, it was really simple, I got it

Reply With Quote
  #18  
Old August 30th, 2003, 10:18 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
thecharking,

Good Job

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > delete dynamic content w/checkboxes


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap