即使存在查询,查询也不会返回任何数据?

时间:2019-06-17 16:29:18

标签: php sql

编程语言: SQL,PHP

课程: 页面,过滤器,表格(全部用PHP编写以呈现格式化的页面,纯CSS过滤器和标准html表格)

外部图书馆: PDO:PHP数据对象https://www.php.net/manual/en/book.pdo.php

==================

我正在创建一个带有过滤器的前台展示台,所有过滤器都会根据用户的选择进行过滤。

但是,当我单击过滤器时,最后一个过滤器将输出null。

$activityOutput = "select id, Activity_Types_ID from activity_outputs where Activity_Types_ID = $activities and Start_Date = $startdates and Last_Name = $lastname";
    $where = "where activity_outputs_id in ($activityOutput)";

$ where变量最终为null,不允许出现任何数据。

不确定为什么会这样

在后端,我运行了相同的查询,并显示了具有相应ID的实际数据。

我尝试了这两种方法来获取$ activityOutput(请参见嵌套的if语句),但这也会在附带的查询中返回null

以$ activityinfo形式进行的$ activityOutput的两个试验

$activityinfo = mysql_fetch_row($db->query("select id from activity_outputs where Activity_Types_ID = $activities and Start_Date = 
$startdates and Last_Name = $lastname"));

$activityinfo = $db->query("select id from activity_outputs where Activity_Types_ID = $activities and Start_Date = $startdates and Last_Name = $lastname")->fetch(PDO::FETCH_NUM);

我再次回应了上面的两个陈述,但是什么也没有。

<?php

require_once("../../classes.php"); //Pull in the appropraite classes

if(!($admin)) goback("Error: Not authorized.");
$_SESSION["back"]="previouspage"; 



if(isset($_GET["name"])) {$_SESSION["lastname"] = 0; 
$_SESSION["state"]=0; $_SESSION["city"]=0; $_SESSION["activites"] = 0; $_SESSION["startdates"] = 0; }
if(isset($_GET["lastname"])) { $_SESSION["state"]=0; $_SESSION["city"]=0; $_SESSION["activites"] = 0; $_SESSION["startdates"] = 0; }
if(isset($_GET["state"])) { $_SESSION["city"]=0; $_SESSION["activities"] = 0; $_SESSION["startdates"] = 0; }
if(isset($_GET["city"])) { $_SESSION["activities"] = 0; $_SESSION["startdates"] = 0;  }
if(isset($_GET["activities"])) $_SESSION["startdates"] = 0;

$page=new Page;

$title="Participation Tracker";


$page->datatable(TRUE); //Tell the page we are creating a table

$page->start($title);

$_SESSION["fname"]=$title;

//Set the filters
$filter=new Filter;
if($last>0) {
$lastname=$last; $firstname=$first; 
$_SESSION["firstname"]=$firstname;
}else{
    $filter->start($db);
    $states=$filter->table("firstname" //possible where clause//);
    $where = ""; 
    if($firstname>0){ 
        $lastname=$filter->table("lastname","First_Name=$firstname");
        if($lastname > 0){
            $lastname = $_SESSION["lastname"];
            $whereclause = "id in (select distinct state from states where Last_Name=$lastname)";

            $states = $filter->table("states", $whereclause);
                if($states > 0){
                $whereclause = "State_ID = $states"; 
                $cities = $filter -> table("cities", $whereclause);
                if($cities > 0){
                    $whereclause = "id in (select Activity_Types_ID from activity_outputs where City_ID = $cities and Last_Name = $lastname )";
                    $activities = $filter->table("activity_types", $whereclause);
                    if($activities > 0){
                       ## Get an array of dates



                        $startdates = $filter->query("Start_Date", "select distinct Start_Date, Start_Date from acitity_outputs where Activity_Types_ID = $activities  and City_ID = $cities ");

// This function gets key value pairs associated as strings// 



                        if($startdates > 0){
                            $activityOutput = "select id, Activity_Types_ID from activity_outputs where Activity_Types_ID = $activities and Start_Date = $startdates and Last_Name = $lastname";
        $where = "where activity_outputs_id in ($activityOutput)";




                        }

                    }
                }
            }
        }
    }
    $filter->end();
}


if($startdates > 0){ ## the closest filter to everything

    $grid=new Table;
    $grid->start($db);
    $grid->smartquery2("particpation_outputs", $where); //This selects everthing from the table and prints it

}else{echo("<p>First, select a First Name.</p>\n");}
$page->end();
?>

我希望

Firstname|Lastname|State|City|Activity|StartDate
John|Smith|NY|NY|StackOverFlowGetTogether|06/17/2019

但是我什么也没得到。

0 个答案:

没有答案