PHP/MYSQL随机足球赛程表

发布于 2025-01-02 10:29:01 字数 344 浏览 4 评论 0原文

我的足球经理锦标赛需要帮助。 我试图将在游戏中注册的所有团队随机插入到名为“时间表”的表中。 数据库将包含列 id、team1、team2、日期、时间。 我知道如何手动执行此操作,但如果有 50 个团队并找出他们希望没有挑战的团队,则需要花费很多时间。以及如何让所有球队每天都打一场比赛。

<?php
mysql_query("INSERT INTO timetable (id, team1, team2, date, time) VALUES ('','Blue','Red','2011-02-06','18.00')")
?>

我知道我的英语不是最好的,但我希望你能懂。 无论如何谢谢,

I need help with my football manager tournament.
I am trying to insert all teams that are registered in the game into a table called "timetable" randomly.
The database will have the columns id, team1, team2, date, time.
I know how to do this manually but it will take to much time if it's like 50 teams and to figure out wish team they haven't challenge. And how to make that all teams play one match everyday.

<?php
mysql_query("INSERT INTO timetable (id, team1, team2, date, time) VALUES ('','Blue','Red','2011-02-06','18.00')")
?>

I know my English is not the best but I hope you get it.
Thanks any way,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

(り薆情海 2025-01-09 10:29:01

据我了解你的问题,你希望每支球队都与其他球队比赛吗?这很简单。只需循环遍历团队即可。

<?php
$teams = array('Red Team', 'Blue Team', 'Yellow Team', 'Green Team');
foreach($teams as $team_one) {
  foreach($teams as $team_two) {
    mysql_query("INSERT INTO timetable (team1, team2) VALUES ('$team_one', '$team_two')");
  }
}
?>

您可能还想编写一个匹配日期计算算法。

如果您的 $teams 数组是用户提供的,出于安全原因,您可能希望使用 mysql_real_escape_string() 转义您的输入。

mysql_query("INSERT INTO timetable (team1, team2) VALUES ('".mysql_real_escape_string($team_one)."', '".mysql_real_escape_string($team_two)."')");

有关安全性的详细信息,请阅读 关于 mysql_real_escape_string( ) 和/或 google 有关 SQL 注入的信息

As far as I have understood your question, you want every team to play against every other team? This is simple. Just loop over the teams.

<?php
$teams = array('Red Team', 'Blue Team', 'Yellow Team', 'Green Team');
foreach($teams as $team_one) {
  foreach($teams as $team_two) {
    mysql_query("INSERT INTO timetable (team1, team2) VALUES ('$team_one', '$team_two')");
  }
}
?>

You might also want to write a match date calculation algorithm.

If your $teams array is user supplied you probably want to escape your inputs with mysql_real_escape_string() for security reasons.

mysql_query("INSERT INTO timetable (team1, team2) VALUES ('".mysql_real_escape_string($team_one)."', '".mysql_real_escape_string($team_two)."')");

For details about security, please read the PHP manual about mysql_real_escape_string() and/or google about SQL injection

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文