Запрос с функцией pagenavi не работает, а функция get работает - PullRequest
0 голосов
/ 28 февраля 2019

У меня такая проблема при создании расширенного поиска, и теперь, как и в параметре поиска, я выберу суточную дозу, т.е. она выполнит условные инструкции $ Usee-> GroupBy ("date");Он получает сообщение

Цитата SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dat' in 'group statement' (SQL: select count(*) as aggregate from пользователь left join продукт on продукт . id = пользователь . id_products left join forwarding_description on пользователь . id= forwarding_descriptions . id_usees left join описание on описание . ID = forwarding_descriptions . id_descriptions where usees * одна тысяча двадцать один * id_users * +1022 * продукты * один тысяча двадцать три * ID in (160) group by DAT * тысяча двадцать пять*

Blockquote Так же, как если бы он вообще не делал все эти selectRaws, но, в свою очередь, если у него нет этой опции, дневная доза работает все хорошо и только не работает для paginate для get works и дляsimplepaginate также работает неправильно, давая код курса.

public function createQuestions($bool) {
    $usee =  usee::query();
    $hour = $this->selectHourStart(Auth::User()->id);
    $usee
            ->selectRaw("products.name as name")
            ->select( DB::Raw("(DATE(IF(HOUR(usees.date) >= $hour, usees.date,Date_add(usees.date, INTERVAL - 1 DAY) )) )  AS dat "))

            ->selectRaw("hour(usees.date) as hour")
            ->selectRaw("sum(usees.portion) as por")
            ->selectRaw("day(usees.date) as day")
            ->selectRaw("month(usees.date) as month")
            ->selectRaw("year(usees.date) as year")                
            ->selectRaw("usees.portion as portion")
            ->selectRaw("usees.date as date")
            ->selectRaw("descriptions.description as description")
            ->selectRaw("descriptions.date as date_description")
            ->selectRaw("usees.id_products as product")
            ->leftjoin("products","products.id","usees.id_products")
            ->leftjoin("forwarding_descriptions","usees.id","forwarding_descriptions.id_usees")
            ->leftjoin("descriptions","descriptions.id","forwarding_descriptions.id_descriptions")

            ->where("usees.id_users",Auth::User()->id);
    if (Input::get("data1") != "") {
        $usee->where("usees.date",">=",Input::get("data1"));
    }
    if (Input::get("data2") != "") {
        $usee->where("usees.date","<=",Input::get("data2"));
    }
    if (Input::get("dose1") != "" and Input::get("day") == "") {
        $usee->where("usees.portion",">=",Input::get("dose1"));
    }
    if (Input::get("dose2") != "" and Input::get("day") == "") {
        $usee->where("usees.portion","<=",Input::get("dose2"));
    }
    if (Input::get("search") != "") {
        $usee->where("descriptions.description","like","%" . Input::get("search") . "%");
    }
    if (Input::get("inDay") != "") {
        $usee->where("descriptions.description","!=", "");
    }

    if ($bool == true) {
            $usee->whereIn("products.id",$this->id_product);
    }

// chodzi o to if (Input :: get ("day")! = "") {

                $usee->groupBy("dat");
                if (Input::get("dose1") != "" ) {
                  $usee->havingRaw("sum(usees.portion) >= " . Input::get("dose1"));
                }
                if (Input::get("dose2") != "" ) {
                  $usee->havingRaw("sum(usees.portion) <= " . Input::get("dose2"));
                }
            }
            else {
                $usee->groupBy("usees.id");
            }
    $list =    $usee->orderBy(Input::get("sort"),"DESC")->paginate(200);
    //foreach ($list as $l) {
      //  print $l->name;
    //}
    return $list;

}

1 Ответ

0 голосов
/ 28 февраля 2019

Я сделал и сейчас пишу ошибку

SQLSTATE [42000]: синтаксическая ошибка или нарушение прав доступа: 1064 В синтаксисе SQL есть ошибка;проверьте руководство, соответствующее вашей версии сервера MariaDB, на предмет правильного синтаксиса для использования рядом с '. date, INTERVAL - 1 DAY) )) ) order by date desc' в строке 1 (SQL: select (DATE (IF (HOUR (usees.date)>> = ')5 ', usees.date, Date_add (usees.date, INTERVAL - 1 DAY)))) как дата, hour (usees.date) как час, count (*) как dos, сумма (usees.portion) как por, день(usees.date) в качестве дня, месяца (usees.date) в качестве месяца, года (usees.date) в качестве года, usees.portion в качестве части, usees.date в качестве даты, description.description в качестве описания, description.date в качестве date_description,usees.id_products как product, products.name как имя из usees left join products on products. id = usees. id_products left join forwarding_descriptions on usees. id =forwarding_descriptions. id_usees левое соединение descriptions на descriptions. id = forwarding_descriptions. id_descriptions, где usees. id_users = 38 и products. id in (160)сгруппировать по (DATE(IF(HOUR(usees. date) >= '5', usees. date,Date_add(usees. date, INTERVAL - 1 DAY) )) ) упорядочить по date desc)

...