Jump to content

Im sure some simple mistake


piznac

Recommended Posts

That code is doing exactly what it is supposed to do. My suggestion is to echo out the loop criteria at the beginning of each loop to see what you are doing. One thing you should look at is the first and last loops. You are looping once for every item in $num2, then the last loop does the same loop, inside that loop. I really don't understand what you are trying to do, so I can't suggest a way to change it.

Well its semms I have over complicated this,.. all I want is to update multiple records at once. I had this before:

 

<?php
  function insert_rows($item_num,$item_desc,$item_qty,$emb_loc1,$num,$size,$artwork,$num2){



$flds = array( 'item_num' , 'item_desc' , 'item_qty' , 'emb_loc1', 'num', 'size', 'artwork');
for($i=0;$i<count($num2);$i++) {
$qtmp = array();
    foreach($flds as $fld){
        if (trim(stripslashes($_POST[$fld][$i])) != ''){
            $qtmp[] = $fld . " = '" . mysql_escape_string(trim(stripslashes($_POST[$fld][$i]))) . "'";
        }
    }
       $q = "UPDATE c_or_details SET " . implode(', ',$qtmp) . " WHERE `subitemnum` = '$num2'";
    $rs = mysql_query($q) or die ('Problem with 1 the query: ' . $q . '<br>' . mysql_error());
    echo "$q<br /> <br />";
    
  

}
}
?>

 

But it would simply use "array" as $num2 var over and over again.

Producing these results:

 

UPDATE c_or_details SET item_num = '1', item_desc = '2', item_qty = '2', emb_loc1 = 'Left Chest', size = 'ONE SIZE', artwork = 'DSCN3361.jpg' WHERE `subitemnum` = 'Array'

 

UPDATE c_or_details SET item_num = '2', item_desc = '2', item_qty = '2', emb_loc1 = 'Left Chest', size = 'ONE SIZE', artwork = 'DSCN3361.jpg' WHERE `subitemnum` = 'Array'

 

I just need to be able to loop through all the records and update WHERE `subitemnum` = '$num2'

 

try

$flds = array( 'item_num' , 'item_desc' , 'item_qty' , 'emb_loc1', 'num', 'size', 'artwork');
for($i=0;$i<count($num2);$i++) {
$qtmp = array();
    foreach($flds as $fld){
        if (trim(stripslashes($_POST[$fld][$i])) != ''){
            $qtmp[] = $fld . " = '" . mysql_escape_string(trim(stripslashes($_POST[$fld][$i]))) . "'";
        }
    }
//       $q = "UPDATE c_or_details SET " . implode(', ',$qtmp) . " WHERE `subitemnum` = '$num2'";
       $q = "UPDATE c_or_details SET " . implode(', ',$qtmp) . " WHERE `subitemnum` = '" . $num2[$i] . "'";
    $rs = mysql_query($q) or die ('Problem with 1 the query: ' . $q . '<br>' . mysql_error());
    echo "$q<br /> <br />";
    
  

}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.