php - Insert multiple rows from array saved in a session into table? -
i'm passing multiple state values stored in session variable, mysql table via php using 1 insert command , i'm wondering if possible insert each state value different row. have id saved in variable insert each state.
$campaign_id
each state stored in session variable.
print_r($_session['stateslist']);
assuming have 2 states saved in $_session['stateslist']
(ny, ca) , campaign id 5, database this
campaign_id state 5 ny 5 ca
i know similar insert multiple rows via php array mysql having problems inserting each state saved in session campaign_id.
here adopted version of want answer
$tags = explode(',', $_session['stateslist']); $sql = array(); $counter=0; foreach( $tags $row ) { $counter++; $sql[] = '("'.$row.'", '.$campaign[counter].')';
assuming here have campaign array contains corresponding campaign ids
} mysql_query('insert table (state, campaign_id) values '.implode(',', $sql));
Comments
Post a Comment