piznac Posted November 13, 2006 Share Posted November 13, 2006 Ok I have this:[code]$flds2 = array('pname','use','job','edate','sdate');[/code]Gathered by a formI need to change it to:[code]$flds2 = array('event','userid','event_type','event_finish','received');[/code]But keep all the values the same. Can anyone help me on how to do this? Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/ Share on other sites More sharing options...
wildteen88 Posted November 13, 2006 Share Posted November 13, 2006 I do not see any keys in your arrays. You just have a list of values stored in the fld2 array.All you'll need to do is this:$fld2[0] = 'event'That will now make the fld2 array like this:array('event','use','job','edate','sdate') Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/#findComment-124046 Share on other sites More sharing options...
piznac Posted November 13, 2006 Author Share Posted November 13, 2006 Ok Im a bit confused,. These are coming off a form where thier is an unknown amount of them.[code]<table width='856' cellspacing='0' cellpadding='0'> <tr> <td width='48'><label> <input name='storenum[]' type='text' id='storenum' size='8' /> </label></td> <td width='145'><label> <input name='address[]' type='text' id='address' /> </label></td> <td width='149'><label> <input name='city[]' type='text' id='city' /> </label></td> <td width='34'><input name='state[]' type='text' id='state' size='5' /></td> <td width='60'><label> <input name='zip[]' type='text' id='zip' size='10' /> </label></td> <td width='62'><input name='phone[]' type='text' id='phone' size='10' /></td> <td width='60'><input name='fax[]' type='text' id='fax' size='10' /></td> <td width='92'><input name='assignemp[]' type='text' id='assignemp' size='10' /></td> <td width='92'><label> <input name='sdate[]' type='text' id='sdate' onfocus='showCalendarControl(this);'/> </label></td> <td width='92'><label> <input name='edate[]' type='text' id='edate' onfocus='showCalendarControl(this);'/> </label> <input name='pname[]' type='hidden' value='$fname' /> <input name='status[]' type='hidden' id='status' value='N' /> <input name='images[]' type='hidden' id='images' value='N' /> <input name='files[]' type='hidden' id='files' value='N' /></td> <input name='use[]' type='hidden' id='use' value='$user' /> <input name='job[]' type='hidden' id='job' value'Project' /> </tr>[/code]then I use this to put the data in the database[code]$flds = array('storenum','address','city','state','zip','phone','fax', 'assignemp', 'pname', 'sdate', 'edate', 'status', 'images', 'files' );for($i=0;$i<count($_POST['storenum']);$i++) { $qtmp = array(); foreach($flds as $fld) if (trim(stripslashes($_POST[$fld][$i])) != '') $qtmp[] = $fld . " = '" . mysql_escape_string(trim(stripslashes($_POST[$fld][$i]))) . "'"; $q = "insert into subjob set " . implode(', ',$qtmp); $rs = mysql_query($q) or die ('Problem with the query: ' . $q . '<br>' . mysql_error());[/code]what I need to do is take about 5 of those and put them in an other table as well. Prehaps I am asking the wrong thing,.. not sure. But if I changed the name like that would it change the value? Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/#findComment-124053 Share on other sites More sharing options...
sasa Posted November 13, 2006 Share Posted November 13, 2006 try[code]<?php$flds2 = array('pname','use','job','edate','sdate');$flds2a = array('event','userid','event_type','event_finish','received');$f = array_combine($flds2,$flds2a);// your code// ...foreach ($f as $key => $value) { if (trim(stripslashes($_POST[$key][$i])) != '') $qtmp[] = $value . " = '" . mysql_escape_string(trim(stripslashes($_POST[$key][$i]))) . "'"; // etc.}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/#findComment-124122 Share on other sites More sharing options...
sasa Posted November 13, 2006 Share Posted November 13, 2006 try[code]<?php$flds2 = array('pname','use','job','edate','sdate');$flds2a = array('event','userid','event_type','event_finish','received');$f = array_combine($flds2,$flds2a);// your code// ...foreach ($f as $key => $value) { if (trim(stripslashes($_POST[$key][$i])) != '') $qtmp[] = $value . " = '" . mysql_escape_string(trim(stripslashes($_POST[$key][$i]))) . "'"; // etc.}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/#findComment-124123 Share on other sites More sharing options...
piznac Posted November 13, 2006 Author Share Posted November 13, 2006 Hey thanks man,.. but this is a version 5 only function? Shame on me for telling you what version I used. It is now in my sig,.. is this function available in 4.4.4 Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/#findComment-124166 Share on other sites More sharing options...
piznac Posted November 13, 2006 Author Share Posted November 13, 2006 Oh wait just found array_merge() ;D Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/#findComment-124167 Share on other sites More sharing options...
sasa Posted November 14, 2006 Share Posted November 14, 2006 OKtry[code]<?phpfunction my_arr_comb($a,$b){ foreach ($a as $key => $value) $out[$value] = $b[$key]; return $out;}$flds2 = array('pname','use','job','edate','sdate');$flds2a = array('event','userid','event_type','event_finish','received');$f = my_arr_comb($flds2,$flds2a);// your code// ...foreach ($f as $key => $value) { if (trim(stripslashes($_POST[$key][$i])) != '') echo $qtmp[] = $value . " = '" . mysql_escape_string(trim(stripslashes($_POST[$key][$i]))) . "'"; // etc.}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27137-change-array-names/#findComment-124535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.