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

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -