...

View Full Version : Resolved stuck on an array



harkly
01-31-2012, 10:26 PM
I have a 2 forms that work separetly but I have them nested, from what I've read I shouldn't do this. The nested forms are working except for the format which makes the container box double in length, no matter what I do. So I am trying to do it the proper way but cannot figure out how to combine my 2nd array with the main one.

Would appreciate some help :)

This is the main form, it allows you to select messages or a message and set it to something different. Think of email but with check boxes.


<form action='' method='POST' name='myForm' id='user'>
<div id='newMsgButtons'>
<input type='submit' name='unread' value='Mark Unread' class='btn' onmouseover=\"this.className='btn btnhov'\" onmouseout=\"this.className='btn'\">&nbsp;&nbsp;<img src='img/line.png' width='1' height='13'>&nbsp;
<input type='submit' name='read' value='Mark Read' class='btn' onmouseover=\"this.className='btn btnhov'\" onmouseout=\"this.className='btn'\">&nbsp;&nbsp;<img src='img/line.png' width='1' height='13'>&nbsp;
<input type='submit' name='delete' value='Delete' class='btn' onmouseover=\"this.className='btn btnhov'\" onmouseout=\"this.className='btn'\">
</div>
<div id='selectAll'>Select: <a href=\"javascript:selectToggle(true, 'myForm');\">All</a>, <a href=\"javascript:selectToggle(false, 'myForm');\">None</a></div> ";

echo"<span class='checkbox'><input type='checkbox' name='answers[]' value='$id'></span>";


Once your selection has been made it kicks it to this code and process it (there is more code this is just one)


$my_array = $_POST['answers'];

// sets message to Unread status
if($_POST['unread']){
$totalIDs = count($my_array);
for ( $i=0; $i < $totalIDs; $i++ ) {
$sql2 = mysql_query("SELECT sender FROM nudges WHERE id='$my_array[$i]'");
while($r = mysql_fetch_array($sql2)) {
$sender=$r['sender'];

$query12 = ("UPDATE nudges SET r_status=0 WHERE id='$my_array[$i]'");
$result12 = mysql_query($query12) or die(mysql_error());
} // END while
} // END for
} // END if($_POST['unread'])



So now I want to take the 2nd form and be able to combine with the main form


$query7 = mysql_query("SELECT * FROM blockUser WHERE blockUserID='$clientID' AND blockID='$sender'");
$num_rows = mysql_num_rows($query7);

if ($num_rows >= 1 ) {
echo "<img src='img/delete2.png' title='Blocked'>";
}
else {
echo "
<input type='hidden' name='block2' value='$sender' />
<input type='image' value='Block' src='delete.png' title='Block'>
";
}

This is its processing code


if($_POST['block2']){
//checking to see that user is in the saved, if it is removing it
$result2 = mysql_query("SELECT * FROM saveUser WHERE userID='$clientID' AND saveID='$block_array[$i]'");
$num_rows = mysql_num_rows($result2);

// deleting from table
if ($num_rows >= 1 ) {
$query1 = "DELETE FROM saveUser WHERE userID='$clientID' AND saveID='$block_array[$i]'";
$result = mysql_query($query1) or die(mysql_error());
}

//checking to see that user is in the saved, if it is removing it
$result3 = mysql_query("SELECT * FROM blockUser WHERE blockUserID='$clientID' AND blockID='$block_array[$i]'");
$num_rows3 = mysql_num_rows($result3);

if ($num_rows3 == 0 ) {
// now inserting info to block the user from appearing
$query2 = ("INSERT INTO blockUser VALUES(NULL,'$clientID','$block_array[$i]')");
$result2 = mysql_query($query2) or die(mysql_error());
}
}


I have modified the form and the processing code for an array but cannot get anything to work.

I've been working on this all day and finally decided that I need help, if someone can point me in the right direction.

abduraooft
02-01-2012, 11:07 AM
You can't nest two forms as it'll produce an invalid markup. Think about something else.

harkly
02-01-2012, 03:08 PM
I know which is why I am asking for help with my array

abduraooft
02-01-2012, 03:19 PM
So now I want to take the 2nd form and be able to combine with the main form
Sorry, but where's your second form?

harkly
02-01-2012, 03:48 PM
The 3rd code box was the second form, which I have tried to convert to work with the array.

The 4th code box is the processing for that form.


this is was it used to be


$query7 = mysql_query("SELECT * FROM blockUser WHERE blockUserID='$clientID' AND blockID='$sender'");
$num_rows = mysql_num_rows($query7);

if ($num_rows >= 1 ) {
echo "<img src='img/delete2.png' title='Blocked'>";
}
else {
echo "
<form ......>
<input type='hidden' name='block2' value='$sender' />
<input type='image' value='Block' src='delete.png' title='Block'>
</form>


";
}


My guess is that I need to take
name='block2' value='$sender'
and turn that into an array
name='block2[]' value='$sender'

When I do that I just get the very last one to 'process'
ie.
if I have 3 names
John
Mike
Sue

and I select John, Sue is the one that is processed



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum