Jump to content

Two Checkbox Save Like Array Into One Column In Database


balkan7

Recommended Posts

Hello guys

I'm tried to save data from 2 checkbox into one column in database and retrieve.

 

In this case i have this:

<?
$test = array(1 => "A", 2 => "B");
foreach ($test as $k => $v) {
echo "<input type=\"checkbox\" name=\"c\" value=\"$k\"> $v <br>";
}
?>

If those 2 checkbox selected i want save in base like array 1,2

After this check from database if column data is:

1 = show pic 1

2 = show pic 2

1,2 (array) = show pic 3

Link to comment
Share on other sites

Hello Barand

How can add for each checkbox (checked='checked')

$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM table WHERE id=$id");
$data = mysql_fetch_array($sql);
$checkbox = data['c'];

$test = array(1 => "A", 2 => "B");
foreach ($test as $k => $v) {
if ($checkbox == $k) { $checked = " checked='checked'";
echo "<input type=\"checkbox\" name=\"c[]\" value=\"$k\"$checked> $v <br>";
}

How can i retrieve if column:

c == 1 only checked A

c == 2 only checked B

c == 3 checked A and B ?

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.