0

在我的工作中,我们有一个模块/网络应用程序,它查询我们的数据库,寻找那些已经回复了再次和我们住在一起的学生(我们是住宿和餐厅)——无论是在我们的公寓还是宿舍。当前的应用程序需要很长时间才能运行,我被要求进行优化,让用户可以选择所讨论的学生是我们公寓的居民(下面的 Jardine)还是住在宿舍里。我有一个基本的 if 语句,它根据从 html 选择菜单中的选择来构造查询,然后使用构建的 sql 语句运行查询。出于某种原因,当我实施此更改时 - 没有返回任何结果。任何帮助表示赞赏!我们总共运行 3 个查询,一个主要查询获取所有居民,另一个用于检查“撤离意图 (ITV)”

try
{       
    if (isset($_POST['select'])) 
    {
        if ($_POST['select'] == 'jardine') 
        {
            $jardine = true;    // Neighborhood and Apartments include the Jardine under 'Site_name' column
            $query = "SELECT * FROM av_user_hms_PatronAssignments a WHERE NOW() BETWEEN ElementStart AND ElementEnd 
                    AND a.Site_name LIKE '%Neighborhood% AND a.Site_name LIKE '%Apartments%'
                    ORDER BY Last_Name, First_Name";
        }
        else
        { 
            $jardine = false;   // Everything else is Residence Halls
            $query = "SELECT * FROM av_user_hms_PatronAssignments a WHERE NOW() BETWEEN ElementStart AND ElementEnd 
                    AND a.Site_name NOT LIKE '%Neighborhood% AND a.Site_name NOT LIKE '%Apartments%'
                    ORDER BY Last_Name, First_Name";
        }

        $hms = new hms_helper();

        // Run the query
        $hmsRows = $hms->query_a($query);           

        //see if user has completed RSVP application
        $query = "SELECT * FROM rsvp.application WHERE wid = ? AND termID = ?";
        $apps = $mysqli->prepare($query) or throwNewException("Prepare error:".$mysqli->error." ".$query);
        $term = getCurrentTerm();
        $apps->bind_param("ii", $stmtArg,$term);


        if ($jardine)
        {           
            // also check Jardine Intent to Vacate
            $query = "SELECT * FROM ITV.ITV WHERE WID = ? AND STR_TO_DATE(vacate_date,'%m/%d/%Y') > '".date("Y")."-01-01';";
            $itv = $eITV->prepare($query) or throwNewException("Prepare error:".$eITV->error." ".$query);
            $itv->bind_param("i", $stmtArg);
        }

        foreach($hmsRows as $k=>$a)
        {
            //$lastWID is used to keep track of last wid so that no entry is duplicated
            $stmtArg = (int)$a["wid"];
            $apps->execute();
            $appResult = $apps->get_result();// get the result back

            if ($jardine)
            {
                $itv->execute();
                $itvResult = $itv->get_result();
                if($itvResult->num_rows > 0) // if they are planning to leave jardine unset them
                {
                    unset($hmsRows[$k]);
                } 
            }

            if($appResult->num_rows > 0) // if they have an application unset them
            {
                unset($hmsRows[$k]);// removes this entry from the array so it won't be displayed.
            }
            elseif($a['ID_Number'] == $lastWID)// don't show duplicates
            {
                unset($hmsRows[$k]);
            }               
            $lastWID = $a['ID_Number'];
        }
    }
} 

笔记:

  • hms_helper 类中的所有内容都可以正常工作
  • 我已经使用我们的 ODBC 查询工具运行了查询,并且所有这些都有效
  • $_POST['select'] 被正确传递,我有一些 echo 语句来检查这个
  • 执行调用是运行 $itv 和 $apps 的查询(准备)
4

0 回答 0