Jul 25, 2008

For Each Loop Help

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

For Each Loop Help

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

 

 

 


Reply

xJedix
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : loop

  1. Loop Through Form - How do you do it? (8)
    In ASP you'd do this: CODE For Each Field in Request.Form So how do you do it in PHP? I
    want to loop through a form, check to see if it has a value and if so, append to a string to send as
    the body of my email....
  2. Php Date() Problem [resolved] - date() seems to loop same ninute. (4)
  3. Help Needed With Directory/file Listing Code Infinite Loop - Made an infinite loop but why is this so? (5)
    Hi all ive got a small and simple (for the moment atleast /unsure.gif"
    style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> )file and directory
    listing script in php as follows CODE $dir = "."; $num = 0; $file =
    scandir($dir); while($file = scandir($dir)){     echo
    $file[$num];     echo "<BR>";     $num = $num + 1;     
    }; the concept is simple enough, the directory to start with is the current one, so scan this
    directory and wh...
  4. For Loop - for loop problem (5)
    i'd like to make for loop which dependes on a $_GET variable: here is my tries: CODE
    if (isset($_GET['date']) {
    switch($_GET['date'])     {         case 'asc': $exp1
    = "$x>0"; $exp2 = "$x=$total";             $condition =
    '$x++';             break;         case 'desc'; $exp1 =
    "$x=$total"; $exp2 = "$x>0";             $condition =
    '$x--';             bre...
  5. While Loop - how to stop the timeout (9)
    I have written a piece of code that is to make a forum which contains a table consiting of two
    colums and a determind number of rows with a while loop, however when I test the page it goes and
    goes, and then returns an error stating that the maximum 30 second limit has been reached, I
    understand what that means I just don't know why it's looping forever: CODE while
    ($weightnum > 0); { echo "<tr>";    echo  
    '<td><input name="wname"' . $appendval . ' type="text"
    id="wname...



Looking for loop

Searching Video's for loop
advertisement



For Each Loop Help



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE