Jump to content

Checkbox blues


ksmatthews

Recommended Posts

HI there,

 

I have the following checkboxes where I am using an array called check[] ...

 

<input name = "check[]" type = "checkbox" value = 'somevalue1' />

<input name = "check[]" type = "checkbox" value = 'somevalue2' />

<input name = "check[]" type = "checkbox" value = 'somevalue3' />

 

When selected by the user, I wish to delete the selected records using this code ...

 

// capture checkbox data

$data = $_POST['check'];

 

// start delete loop

foreach ($data as $key => $value )

  {

    // create SQL string

    $SQL = 'DELETE FROM ' . $table . ' WHERE name = "' . $value .'"';

 

    // run SQL query

    code goes here

  }

 

This code works fine ! BUt the javascipt functionality that references it does not work !

 

What I would like to know is how I can do the same thing but AVOID using the check[] array, by using checkboxes like this ...

 

<input name = "check" type = "checkbox" value = 'somevalue1' />

<input name = "check" type = "checkbox" value = 'somevalue2' />

<input name = "check" type = "checkbox" value = 'somevalue3' />

 

Has anyone got any good references for dealing with checkboxes in php ?

 

thanks,

 

Steven Matthews

 

 

Link to comment
Share on other sites

ok i used a for loop e.g.

 

for($i=0;$i<10;$i++)

{

  echo "<input type=\"checkbox\" name=\"red[$i]\">

}

 

then to process:

 

for($j=0;$j<10;$j++)

{

  $valueofcheckbox = $red[$i];

  if($valueofcheckbox=="on")

  {

      echo "$j is ON";

  }

  else

  {

      echo "$j is OFF";

  }

}

 

i'm sure you can figure out how to put this in a while loop if you're using a mysql recordset.

Link to comment
Share on other sites

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.