简体   繁体   中英

check mysql result against array for duplicates

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

$resultset !== $resultSet

You've stored in resultSet, and testested resultset.

因为您要使用变量名称-$ resultSet来创建数组,并通过array_intersect()传递的结果是$ resultset。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM