for loop with update query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizardry
    New Member
    • Jan 2009
    • 201

    for loop with update query?

    i think i need to have a for loop with this update query but i have not used a for loop with an update query before. can you show me an example ?

    Code:
    <?php
    
    $fooArray = explode(',',$_SESSION['foo_string_id']);
    
    $count_size = count($fooArray);
    
    $t = 0;
    
    while ($t < $size) {
    
    						// the data table
      					 $Foo0 =  GetSQLValueString(isset($_POST['Foo']) ? "true" : "", "defined","'Y'","'N'")[$t];
    					 $FooDefault0 =  GetSQLValueString(isset($_POST['FooDefault']) ? "true" : "", "defined","'Y'","'N'")[$t];
    					 $FooSize0 =  GetSQLValueString($_POST['FooSize'], "int")[$t];
    foreach( $fooArray as $fooId ) {
     
    $update = sprintf("UPDATE footable SET `Foo`='$Foo0', FooDefault='$FooDefault0', FooSize='$FooSize0' WHERE FooId=$fooId");
    
    mysql_select_db($database_foo, $Foo);
      $Result = mysql_query($update, $Foo); // or die(mysql_error());
    
    
    
    	} // end of query
    } // end of while loop
    
    ?>
    thanks in advance for your help!
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Code:
    for ($i = 0; $i < $size; $i++) {
    
      // do stuff
    }
    Dan

    Comment

    Working...