SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to combine two variables but have not been successfull. Here is the scenerio:

    A page is generated with X number of entries and by each one of those entries is a CHECKBOX named delete1, delete2 ... When the user selects one or more of these boxes and presses delete, I want the script to go and delete all the respective entries from the database. I can't get the variables to combine however.

    Ex:

    this is the line that is passed on to the delete script, in this case the user selected entry 1 and 3 to be deleted:

    mydomain.com/process_delete.php3?delete1=entry1&delete3=entry3&pd=Delete+Selected+Jobs&obj=29

    I am trying to combine two variables like so:

    for ($cnt=1; $cnt <= $obj; $cnt++) {
    $delete = ("$delete$cnt");
    print "$delete";
    }

    The $delete var is not attaching the $delete values passed from the other page but only the $cnt value giving me a big incremental number.

    How can I fix this, or what is a better way to approach this type of deletion?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried following what you did there, but got a little lost. Normally when I do something like this I make my checkboxes into an array and assign the id for the value:

    Code:
    <input type="checkbox" name="delids[]" value="2">
    <input type="checkbox" name="delids[]" value="3">
    <input type="checkbox" name="delids[]" value="7">
    <input type="checkbox" name="delids[]" value="9">
    <input type="checkbox" name="delids[]" value="12">
    No when the form gets submitted all the checkboxes that were checked will have the id in the array $delids. So on to the part that deletes them
    PHP Code:
    foreach($delids as $key => $val) {
    $result mysql_query("DELETE from tablename WHERE idccolumn = $val");



    Hope that helps a bit
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey freddy!

    As you know I'm very new to PHP and I was wondering if you would explain to me exactly what that foreach() does there... all the control structures I've been using in PHP are if, else, while, and elseif... I think I know the basics of foreach, but not sure... thanks!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  4. #4
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    foreach()

    foreach() is used to loop through an array. I find it easy to learn by simple examples, so here you go:
    Example 1.
    PHP Code:
    <?
    $names 
    = array("Rob","Louie","Wheels","Snake","Joey","Spike");
    foreach(
    $names as $name)
    {
         echo 
    "$name, ";
    }
    ?>
    output:
    Rob, Louie, Wheels, Snake, Joey,Spike

    You can also use foreach() to loop through an array that contains both a key and a value.

    Example 2.
    PHP Code:
    <?
    $names_status 
    = array(
                           
    "Rob"=> "retarded",
                           
    "Louie"=>"the biggest loser I know",
                           
    "Wheels"=>"a guy with Nice glasses",
                           
    "Snake"=>"a tall freak of nature",
                           
    "Joey"=>"a Degrassi God"
                           
    );

    foreach(
    $names_status as $name=>$status)
    {
             echo 
    "$name is $status<br>";
    }
    ?>
    output:
    Rob is retarded
    Louie is the biggest loser I know
    Wheels is a guy with Nice glasses
    Snake is a tall freak of nature
    Joey is a degrassi God

    foreach() is basically like using
    for($i=0;$i<=count($array);$i++)
    {}

    hope that helps.
    Last edited by jrap; Mar 20, 2001 at 20:39.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me guess that array of names, Degrassi. And that Louie kid was the coolest, he was the one who all the other kids wanted to hang around. Ha Ha too funny! Good One Rob.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That does help, thanks all, much appreciated.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •