Jump to content

DOH! Got stuck CheckBoxes and Dynamic Arrays.. Help?


monkeytooth

Recommended Posts

Ayy, hate when I stump myself, and I am probably putting to much thought into the concept. So anyone wanna throw me a bone help me out?

 

I have a dynamically generated list pulled via PHP from mySQL so the info is never the same as the database is for ever expanding. Anyway, listed out onto the page I want to give myself the ability to mass delete entries, so im figuring something along the concept of checkboxes next to all that is listed from there check off the ones I want deleted and hit the magic button to delete them. Now Im almost positive I can get it to do everything I want it to do minus one factor..

 

I cant wrap my mind around making the array of checkboxes checked. any suggestions?

sorry for the delay in response ended up having to take off...

 

What im trying to do, well have done to one extent or another is.. from my database pull a list of stuff out for display. with this results i want a check box next to each one, which making that physically happen no problem.

 

The purpose of the check boxes however is so that I can check off specific items from the display and where upon checking them if I hit the "Delete" button.. It will create an array out of the check boxes checked and then I can cycle that through a while loop or something to delete/update the entries in the database.

 

The part I'm having issues wrapping my head around is.. how do I create this array of information given off the check boxes checked. As the data is never consistent as the DB is constantly growing. The only consistent thing I may have about this concept is to display 25 or 50 results per page. That aside I need to get my "emIDn" value (its a column on the table im working with..) and place that into said array if the check box is checked.

 

So I am open to suggestions :-)

So just display each item from the database like so, with the ID of the item as the value:

<input type="checkbox" name="emIDn[]" value="1" />First Thing

<input type="checkbox" name="emIDn[]" value="2" />Second Thing

<input type="checkbox" name="emIDn[]" value="3" />Third Thing

 

And the code to process this would look something like this:

if (isset($_POST['delete'])) 
{
    foreach ($_POST['emIDn'] as $emIDn) 
    {
        $query = "DELETE FROM table WHERE emIDn = " . mysql_real_escape_string($emIDn);
        mysql_query($query);
    }
}

Archived

This topic is now archived and is closed to further replies.

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