检查 mysql 结果与数组是否有重复项
我对此进行了研究,但没有结果,我想我应该在这里询问,因为 SO 的一群人似乎消息灵通。
情况是这样的。我有一个数据库,其中存储了比赛,以便为我正在开发的联赛应用程序创建结果/时间表。除了我上次的错误检查之外,一切都很好。基本上我想做的是检查表格中选择的球队是否已经在制定日程时选择的日期进行比赛。即 TEAM1 和 TEAM2 将于 2011 年 4 月 20 日进行比赛(这已经在数据库中),当联盟管理员制定时间表时,我想确保这两支球队都不能安排在该日期再次比赛。
这是我到目前为止得到的代码:
//check to make sure none of the teams are already scheduled to play on the same date
$resultarray = "";
$querydate = $_POST['date'];
$queryseason = $_SESSION['SEASON_ID'];
$sql2="SELECT MATCH_TEAM1_ID, MATCH_TEAM2_ID FROM MATCHES WHERE SEASON_ID ='$queryseason' AND MATCH_DATE='$querydate'";
$result2=mysql_query($sql2) or die(mysql_error());
$teamdateerror = false;
$resultSet = array();
while($resultarray = mysql_fetch_array($result2)){
$resultSet[] = $resultarray;
}
$commonteamcheck = array_intersect($resultset,$allteams);
vardump($commonteamcheck);
if ($commonteamcheck != ""){
$teamdateerror = true;
}
上面总是会导致错误:警告:array_intersect() [function.array-intersect]:参数#1不是数组
有什么想法吗?预先感谢您的任何帮助!
I have researched this to no avail and thought I'd inquire here since the group of folks at SO seems to be really well informed.
Here's the situation. I have a database in which I've got matches stored to create a result/schedule for a league app I'm working on. Everything is fine except my last error check. Basically what I want to do is check that the teams selected in a form aren't already playing on the date selected when making the schedule. i.e. TEAM1 and TEAM2 are playing on April 20th, 2011 (this is already in the db) and when the league admin is making up a schedule I want to make sure that neither of those teams can be scheduled to play again on that date.
Here's the code I've got so far:
//check to make sure none of the teams are already scheduled to play on the same date
$resultarray = "";
$querydate = $_POST['date'];
$queryseason = $_SESSION['SEASON_ID'];
$sql2="SELECT MATCH_TEAM1_ID, MATCH_TEAM2_ID FROM MATCHES WHERE SEASON_ID ='$queryseason' AND MATCH_DATE='$querydate'";
$result2=mysql_query($sql2) or die(mysql_error());
$teamdateerror = false;
$resultSet = array();
while($resultarray = mysql_fetch_array($result2)){
$resultSet[] = $resultarray;
}
$commonteamcheck = array_intersect($resultset,$allteams);
vardump($commonteamcheck);
if ($commonteamcheck != ""){
$teamdateerror = true;
}
The above always results in an error : Warning: array_intersect() [function.array-intersect]: Argument #1 is not an array
Any ideas? Thanks in advance for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为您正在使用变量名称 - $resultSet 创建数组并通过 array_intersect() 传递是 $resultset。
Because your are making array with the variable name - $resultSet and passing through array_intersect() is $resultset.
$resultset !== $resultSet
您已存储在 resultSet 中,并测试了结果集。
$resultset !== $resultSet
You've stored in resultSet, and testested resultset.