向表mysql添加多个值

时间:2021-09-05 13:02:42

I am creating a MySQL database and it is storing stats from a game. Right now I am just setting it up and I need to add 80 players with a column for each one that has there goals, assists, etc...

我正在创建一个MySQL数据库,它正在存储游戏的统计数据。现在我只是设置它,我需要添加80个玩家,每个玩家有一个列,有目标,助攻等...

here is my code:

这是我的代码:

INSERT INTO `finalproject`.`Bremners` (
   `stud_id`, 
   `stud_name`, 
   `stud_goal`, 
   `stud_assist`,
   `stud_attendance`, 
   `stud_goalie`
) VALUES (
   '1', 
   'test', 
   '0', 
   '0', 
   '0', 
   '0'
);

But that only inserts one player named "test". Does anyone know how to modify this code so that it adds 80 players each one with a different name? (I making the website with php so if it can be done through php that works to)

但是只插入一个名为“test”的玩家。有谁知道如何修改此代码,以便它添加80个玩家,每个玩家有一个不同的名称? (我用php创建网站,如果它可以通过php工作完成)

Thanks

谢谢

2 个解决方案

#1


3  

Well, you can start off by creating a PHP array of players, then loop through that array and use mysql to add each of those players into the database.

好吧,你可以先创建一个PHP数组的播放器,然后循环遍历该数组并使用mysql将每个播放器添加到数据库中。

$players = array("John", "Jack", "Josh"..."80th Player");

$ players = array(“John”,“Jack”,“Josh”......“80th Player”);

foreach($players as $player):
$player = mysql_real_escape_string($player);
mysql_query("INSERT INTO `finalproject`.`Bremners` (`stud_id`, `stud_name`, `stud_goal`, `stud_assist`,
`stud_attendance`, `stud_goalie`) VALUES ('1', $player, '0', '0', '0', '0')")
endforeach;

I wouldn't use the mysql_.. to insert into database but just to give you the idea I used it.

我不会使用mysql_ ..插入数据库,只是为了给你我使用它的想法。

#2


2  

Try this

尝试这个

INSERT INTO `finalproject`.`Bremners` (
     `stud_id`, 
     `stud_name`, 
     `stud_goal`, 
     `stud_assist`,
     `stud_attendance`, 
     `stud_goalie`
)VALUES 
('1', 'test', '0', '0', '0', '0'),
('2', 'test1', '0', '0', '0', '0'),
('3', 'test2', '0', '0', '0', '0'),
....
('80', 'test79', '0', '0', '0', '0');

#1


3  

Well, you can start off by creating a PHP array of players, then loop through that array and use mysql to add each of those players into the database.

好吧,你可以先创建一个PHP数组的播放器,然后循环遍历该数组并使用mysql将每个播放器添加到数据库中。

$players = array("John", "Jack", "Josh"..."80th Player");

$ players = array(“John”,“Jack”,“Josh”......“80th Player”);

foreach($players as $player):
$player = mysql_real_escape_string($player);
mysql_query("INSERT INTO `finalproject`.`Bremners` (`stud_id`, `stud_name`, `stud_goal`, `stud_assist`,
`stud_attendance`, `stud_goalie`) VALUES ('1', $player, '0', '0', '0', '0')")
endforeach;

I wouldn't use the mysql_.. to insert into database but just to give you the idea I used it.

我不会使用mysql_ ..插入数据库,只是为了给你我使用它的想法。

#2


2  

Try this

尝试这个

INSERT INTO `finalproject`.`Bremners` (
     `stud_id`, 
     `stud_name`, 
     `stud_goal`, 
     `stud_assist`,
     `stud_attendance`, 
     `stud_goalie`
)VALUES 
('1', 'test', '0', '0', '0', '0'),
('2', 'test1', '0', '0', '0', '0'),
('3', 'test2', '0', '0', '0', '0'),
....
('80', 'test79', '0', '0', '0', '0');