Jump to content

change array names


piznac

Recommended Posts

Ok I have this:

[code]$flds2 = array('pname','use','job','edate','sdate');[/code]

Gathered by a form

I 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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

OK
try[code]<?php
function 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
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.