Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> For Each Loop Help
kvarnerexpress
post Dec 12 2005, 07:34 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



I have a page where I list a number of records from my db. Under each record I have a checkbox and a text field. At the bottom of the list I have a submit button. I want to be able to check various boxes and edit the text field then click the button to update all of the records. I currenlty have the following and it updates the records ok (checkbox, I haven't messed with the text field yet) when I first check the boxes but it will not update the db when I uncheck the boxes.

My form:

PHP Code:

CODE

<form name="form1" method="post" action=myscript.php?rid=$rid>

<input name="sortorder" type="text" id="sortorder" maxlength="2" />

<input type="checkbox" name="active1[$rid]" id="active" value="CHECKED" $active />

if(isset($_POST['active1'][$rid]));
$active1=serialize($_POST['active1']);
<input type="Submit" name="btn1" value="Update"
</form>  




My script:

PHP Code:

CODE
<?
header("Location: mypage.php");
include("../my db info.php");
$chkd = "CHECKED";
$db = mysql_connect(localhost,$myid,$mypw);
mysql_select_db($mydb,$db);

$res = mysql_query("SELECT * FROM mytable WHERE NOT (active='$chkd')",$db);
if     ($row = $active1)
{{
foreach ($active1 as $rid => $value1) {
mysql_query("UPDATE articles SET active='$value1' WHERE rid='$rid'",$db);
}}}
else {echo "Grrrr!";}
mysql_close();
Go to the top of the page
 
+Quote Post
xJedix
post Dec 17 2005, 05:07 PM
Post #2


Premium Member
********

Group: Members
Posts: 183
Joined: 27-June 05
From: Minnesota
Member No.: 8,734



I remember doing these before because they are a pain to get them to update if I remember right. Unfortunatly I can't remember where I used them.... otherwise I would show you the code for them because I did get the check boxs to work right.

All I remember is doing if statements to check if they are active or not, and using 1's and 0' for clicked or not. This probably won't help that much, but I figured I might as well say what I remember.

I hope you figure it out, I'll check my site later to see if I have it hidden somewhere wink.gif

xJedix
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Need Help With C Program To Test If A Number Is Prime(12)
  2. Loop Through Form(8)
  3. Redirection Loop(2)
  4. Php Date() Problem [resolved](4)
  5. Help Needed With Directory/file Listing Code Infinite Loop(5)
  6. For Loop(5)
  7. While Loop(9)


 



- Lo-Fi Version Time is now: 30th August 2008 - 02:25 AM