How to combine both array and insert into database php -
if 1 array there example
$values = array(x, y, z);
i adding them database this
foreach ($values $value) { $insertfunction = addvalues($value); }
my arrays:
$array1 = array ( 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 ); $array2 = array ( fb1, or1, fb2, or2, fb3, or3, fb4, or4, fb5, or5 );
but want both array combine , insert them database. how can please me
updated:
when printing post values getting out put this
array ( [0] => 1 [1] => 2 [2] => 1 [3] => 2 [4] => 1 [5] => 2 [6] => 1 [7] => 2 [8] => 1 [9] => 2 ) array ( [0] => fb1 [1] => or1 [2] => fb2 [3] => or2 [4] => fb3 [5] => or3 [6] => fb4 [7] => or4 [8] => fb5 [9] => or5 )
when tried array_merge out put
array ( [0] => 1 [1] => 2 [2] => 1 [3] => 2 [4] => 1 [5] => 2 [6] => 1 [7] => 2 [8] => 1 [9] => 2 [10] => fb1 [11] => or1 [12] => fb2 [13] => or2 [14] => fb3 [15] => or3 [16] => fb4 [17] => or4 [18] => fb5 [19] => or5 )
how insert them in separate columns in table $array1 , $array2
my database table this
1.id 2.username 3.network_id
id primary key network_id values coming in array1 username values coming in array2
edit:
after mentioned seperated columns think understand you're looking for: i'm assuming array1 , array2 in same size.
for($i = 0; $i < count($array1); $i++) { $array2[$i] = (int)$array2[$i]; //"validating" username (an integer) mysql_query("insert yourtablename (`username`,`network_id`) values('".$array2[$i]."','".$array1[$i]."')"); }
result:
tblname:
username: 1 2 1 ...
network_id: fb1 or1 fb2 ...
is looking for?
ignore , merging:
$combined = array_merge($array1 , $array2); //$combined = array ( 1, 2, 1, 2, 1, 2, 1, 2, 1, 2,fb1, or1, fb2, or2, fb3, or3, fb4, or4, fb5, or5 );
Comments
Post a Comment