Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

For Each Loop Help

Recommended Posts

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:

<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:

<? 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();

Share this post


Link to post
Share on other sites

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 ;)xJedix

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.