How to check "SQLSTATE[42S22] error: Column not found: 1054 Unknown column"

Asked

Viewed 7,376 times

0

I wonder how I can verify this error in my code "SQLSTATE[42S22]: Column not found: 1054 Unknown column" private $untamed;

public function RetornaIndoperacionais($ano){

    if($ano == '2016'){
        $_base = "pla_est_2016";  
    }else{
      $_base = "pla_est";
    }

    $Query = ("SELECT i.codiniciativa,
    te.nome as nome_tema,
    iniciativas as cod_te,
    p.observacoes as per_obs,
    te.sequencia as tem_sequencia,
    p.sigla as per_sigla,
    p.nome as nome_perspectiva,
    p.codperspectiva as cod_perspectiva,
    o.sequencia as sequencia_obj,
    o.codobjetivo as cod_obj,
    o.nome as nome_obj,concat(p.sigla, ' ', te.sequencia,
    '.', o.sequencia, '.',i.sequencia) as codigo,i.nome as nom_iniciativa,
    i.sequencia as iniciativa_sequencia,
    i.metas,i.responsavel,i.indicadores,
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) = 2016 AND month(a.data) = 1 ORDER BY a.data DESC LIMIT 1),
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) <= 2016 AND month(a.data) < 1 AND curdate() >= '2016-01-01' ORDER BY a.data DESC LIMIT 1), 0)) as '01',
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) = 2016 AND month(a.data) = 2 ORDER BY a.data DESC LIMIT 1),
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) <= 2016 AND month(a.data) < 2 AND curdate() >= '2016-02-01' ORDER BY a.data DESC LIMIT 1), 0)) as '02',
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) = 2016 AND month(a.data) = 3 ORDER BY a.data DESC LIMIT 1),
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) <= 2016 AND month(a.data) < 3 AND curdate() >= '2016-03-01' ORDER BY a.data DESC LIMIT 1), 0)) as '03',
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) = 2016 AND month(a.data) = 4 ORDER BY a.data DESC LIMIT 1),
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) <= 2016 AND month(a.data) < 4 AND curdate() >= '2016-04-01' ORDER BY a.data DESC LIMIT 1), 0)) as '04',
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) = 2016 AND month(a.data) = 5 ORDER BY a.data DESC LIMIT 1),
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) <= 2016 AND month(a.data) < 5 AND curdate() >= '2016-05-01' ORDER BY a.data DESC LIMIT 1), 0)) as '05',
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) = 2016 AND month(a.data) = 6 ORDER BY a.data DESC LIMIT 1),
    ifnull((SELECT a.percentual FROM $_base.avaliacoes a WHERE a.status = 'A' AND a.codiniciativa = i.codiniciativa AND year(a.data) <= 2016 AND month(a.data) < 6 AND curdate() >= '2016-06-01' ORDER BY a.data DESC LIMIT 1), 0)) as '06' 
    FROM $_base.perspectivas p  
    LEFT JOIN iniciativas te ON p.codperspectiva = te.codperspectiva 
    LEFT JOIN objetivos o ON iniciativas = iniciativas 
    LEFT JOIN iniciativas i ON o.codobjetivo = i.codobjetivo WHERE p.codperspectiva = '5' AND p.status = 'A' AND te.status = 'A' AND o.status = 'A' AND i.status = 'A'ORDER BY p.sequencia ASC,te.sequencia ASC,
    o.sequencia ASC,CAST(i.sequencia AS DECIMAL) ASC" ); 


    //echo "</pre>"; print_r($Query); exit;

    //while ($_indoperacionais = mysql_fecth_array($Query));
    try {
            $this->search = $this->MySql->prepare($Query);
            //$this->search->bindParam(":nome", $this->indoperacionais);
            $this->search->execute();

        } catch(PDOException $e) {
            die($e->getMessage());
        }

        $_result = $this->search->fetchAll(PDO::FETCH_ASSOC);
        return $_result;


   }
}


<?php
 /* codigo para gerar os paramentros  */
    $ano        = $_POST["ano"];
    $_perspectiva = $_POST["perspectiva"];

    if ($_POST["semestre"] == "primeiro") {
        $_parametros = array (
        "ano" => $ano,
        "mes1" => 1, "mes2" => 2, "mes3" => 3,
        "mes4" => 4, "mes5" => 5, "mes6" => 6,
        "nomeMes1" => "Janeiro", "nomeMes2" => "Fervereiro", "nomeMes3" => "Março",
        "nomeMes4" => "Abril", "nomeMes5" => "Maio", "nomeMes6" => "Junho",
        "perspectiva" => $_perspectiva);
    }else if ($_POST["semestre"] == "segundo") {
        $_parametros = array (
        "ano" => $ano,
        "mes1" => 7, "mes2" => 8, "mes3" => 9,
        "mes4" => 10, "mes5" => 11, "mes6" => 12,
        "nomeMes1" => "Julho", "nomeMes2" => "Agosto", "nomeMes3" => "Setembro",
        "nomeMes4" => "Outubro", "nomeMes5" => "Novembro", "nomeMes6" => "Dezembro",
        "perspectiva" => $_perspectiva);
    }else {
        $error = "ERRO";
    }


    //Instanciando a classe
    $_model = new model_Indoperacionais();
    $_indoperacionais = $_model->RetornaIndoperacionais($ano);

        // "<pre>"; print_r ($_indoperacionais);exit;
          echo '<h3 align=left>'.$_perspectiva ["perspectiva"].'</h3>';
          echo '<h1 align=center>'.$ano ["ano"].'</h1>';


     foreach($_indoperacionais as $_indoperacional){
          echo '<tr>';
          echo '<td align=center>'.$_indoperacional['nome_tema'].'</td>';
          echo '<td align=center>'.$_indoperacional['indicadores'].'</td>';
          echo '<td align=center>'.$_indoperacional['responsavel'].'</td>';
          echo '<td align=center>'.$_indoperacional['metas'].'</td>';
          echo '<td align=center>'.$_indoperacional['codiniciativa'].'</td>';
          echo '</tr>';
        //print_r($_parametros);
     }
    ?>

1 answer

2

The error being displayed is Column not found, this means that some field you have in the sql query, you do not have in the database table. Make a comparison and remove this field from the query.

I hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.