douyouzheng2209 2013-05-10 13:44
浏览 94
已采纳

向表mysql添加多个值

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...

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)

Thanks

  • 写回答

2条回答 默认 最新

  • duanji2002 2013-05-10 13:46
    关注

    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.

    $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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度