piznac Posted August 28, 2007 Author Share Posted August 28, 2007 lol,.. ok thanks Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 28, 2007 Share Posted August 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 Yeah that's about where I am... Quote Link to comment Share on other sites More sharing options...
piznac Posted August 28, 2007 Author Share Posted August 28, 2007 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' Quote Link to comment Share on other sites More sharing options...
sasa Posted August 28, 2007 Share Posted August 28, 2007 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 />"; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.