php - Using two arrays with different keys in an mysql update query -
i have array this
$outputs: 269 => string ' sun: 2.495' (length=13) 510 => string ' sun: 1.416' (length=13) another array this
$filenames: 0 => string 'hi35 ' (length=5) 1 => string 'he_41 ' (length=6) and update respective values tried writing code
foreach($outputs $key => $value){ $sql = "update store set d='".$value."' `index` = '".$filenames[$key]."'"; mysql_query($sql); } but there no $filenames[$key] value, because key value $outputs starts 269. 1 case, key value anything.
i tried other way around. i.e.
i combined both array first
$arr3 = array_combine($outputs, $filenames); and tried put combined array in sql query like
foreach($arr3 $key => $value){ $sql = "update store set d='".$key."' `index` = '".$value."'"; mysql_query($sql); } but dint work.. side appreciated...
you can this
$outputs = array( '269' => 'sun: 2.495', '510' => 'sun: 1.416' ); $filenames = array( '0' => 'hi35', '1' => 'he_41' ); $array_complete = array_combine($filenames, $outputs); foreach($array_complete $key => $val) { echo "update store set d='".$val."' `index` = '".$key."'" . '<br>'; } this output
update store set d='sun: 2.495' `index` = 'hi35' update store set d='sun: 1.416' `index` = 'he_41' then remember mysql_ functions deprecated advise switch mysqli or pdo
Comments
Post a Comment