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.

Link to comment
Share on other sites

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'

 

Link to comment
Share on other sites

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 />";
    
  

}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.