Hello guys...actually it's going to be a pretty hard question and probably hard to solve. Here it goes:

I have a table of added members and the same table exists in "remove_members" page where I added a checkbox to each user's picture. The pic/user is supposed to be deleted when the checkbox is ticked. The problem is this - the checkboxes need to be and are processed within PHP and are all concatenated to the pictures. That's why I cannot use them as an array and they won't return anything apart from one value if the array is used. It's because all of them will have the same name after concatenation. The title of the checkboxes returns correct value corresponding to each picture. Any ideas how you can get a value from each individual checkbox ? Regards for any comments. Here's the code:


//members add
$sql_members = mysql_query("SELECT * FROM `auth` WHERE `userName`='".$_SESSION['logged']."'");

while ( $row = mysql_fetch_array($sql_members)) { 
$userName = $row['userName'];
$uid = $row['uid'];

$sql_members_name = mysql_query("SELECT a.userName, a.uid, m.uid, m.friend_id , m.user_id FROM `auth` a LEFT OUTER JOIN `members` m ON a.uid = m.friend_id ");

$sql_members_add = mysql_query("SELECT * FROM `members`,`auth` WHERE auth.uid=members.friend_id AND members.user_id = '$uid' ORDER BY `user_id` DESC");

while ($rows = mysql_fetch_array($sql_members_add)) { 
$friends = $rows['friend_id'];
$user = $rows['userName'];
$user_id = $rows['friend_id'];

//name length
$user = substr($user, 0, 12);

//$strFirstname = strlen($user);
//if ($strFirstname>5) { $user.=".."; }

$f_ex = "members/".$friends."/userImg1.jpg";
if (file_exists($f_ex)) {
$mem_dir_add_pic .= "<form method='post' name='myform' id='myform' action='remove_members.php'><a href='see_member.php?id=$user_id'><img src='members/".$friends."/userImg1.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem2' value='".$user_id."' /></span></form>";
} else { 

$mem_dir_add_pic .= "<a href='see_member.php?id=$user_id'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a>".$mem_dir_add_pic2 ;


$mem_dir_add_pic .= "<html><form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox'  name='del_mem' title='$user_id' value='$user_id'/></span></form></html>";


$mem_check  = $_POST['del_mem'];

if ($mem_check == $user_id)  { 

$proceed = mysql_query("DELETE FROM `members` WHERE friend_id='$mem_check' AND user_id='$uid' ");


[edit] sorry, let me think about that for a moment.

I think that you are going to have to get creative with this. I think that there are actually several ways that you can do this. I won't put it all into code because I am still not exactly sure about everything that you are trying to accomplish here but there are many tools at your disposal. I will give you a one to hopefully get your mind thinking in a different direction.

one option would be to loop through the userids for which you will have one check box for and then loop through all the friends of that user but they will be an array so the name of those checkboxes will be "<?php echo $user_id; ?>:del_mem2[]" so at post you will have several arrays by the names of "userid:del_mem2" and you can just go

foreach($_POST as $key=>&$value) //where value would be the array of all the friends that are being deleted for that member
    $user_id = "";

    if(stripos($key, "del_mem2") !== false && count($value) > 0) //this is a member's friends array
        list($user_id, $strJunk) = explode(":", $key);
        mysql_query("DELETE FROM `members` WHERE friend_id in('" . implode("', '", $value) . "') AND user_id='$user_id'";

First of all - thank you for such a quick and advanced reply and second of all - I will look into it in a minute and post a response how it went. Regards R0bb0b !

Just to confirm if I get you right - the code looks fabuolous. What I do is this:

I place the - checkbox name"del_mem2[]" - but mind that this is an array that it's not working in PHP script when the checkbox is concatenated. Hence , there's no output from the code.

I would like to thank for you replies. The problem is that you can't return string names from concatenated boxes dynamically. Anyway, the arrays in this case won't work. You probably can only fetch an array from a group of boxes within HTML. Regards. David.

To all who might be interested in the correct answer - here's one from the PHP-Forum that I was actually looking for:

while ($row = mysql_fetch_assoc($result)) { 
echo '<input type="checkbox" value="1" name="somename['.$rows['friend_id'].']"> Username: $rows[userName]';

This will return an array of somename[], filled with 1's, 


somename['32'] = 1;
somename['35'] = 1;

if they are checked. If they are not checked... they wont return anything.