php - Adding multiple rows to table with auto_increment column -


im trying insert data table named team. table holds 4 colums. selection_id(primary key), player_name, position, , fixture id.

the selection_id has value of auto_increment. im adding player names , position table. problem is, each value extracts out of arrays, $playnames , $positions, selection_id updates. this: enter image description here

this not want. 5 names should stored (thus storing team selected) in table before selection_id updates. or each new row, new team selection made, selection_id must same.

im not sure how around problem. thought doing query after data has been inserted overwrite selection_id , making rows (in case) equal 117. im sure not effecient way it.

if can give me couple of pointers appreciated. code follows:

if ( isset($_post['submit']) ) {     $player_ids = array_map('intval', $_request['players']);      var_dump($player_ids);      $query = 'select `name`, `position`          `player_info`          `player_id` in (' . implode(',', $player_ids) . ')';      $return_names = mysql_query($query) or die(mysql_error());      while ( $row = mysql_fetch_assoc($return_names) ) {         $selected[] = $row['name'];         $position[] = $row['position'];     }              ($i=0; sizeof($selected) > $i; $i++){                  $sql = mysql_query("insert `team`(`selection_id`,`player_position`,`player_name`) values ('selection_id\"\"','$position[$i]','$selected[$i]')")                   or die(mysql_error());                  echo $selected[$i];                   echo $position[$i];                      echo'<br>';    }  var_dump($selected);           } 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -