I have a table of "disciplines", a table of "students" and a table "students Disciplines", where these students can be enrolled in one or more subjects. These disciplines are shown as checkboxes on the search screen to serve as filters. Now I need to list all the values in the "students" table according to the selected subjects, but I can not.
This is the Query I'm doing:
public function buscaAvancada ($Busca, $Condicao)
{
$oConexao = new conexaoclass();
$oConexao -> abrirConexao();
$sql = "SELECT * FROM Alunos
INNER JOIN Disciplinas
WHERE Alunos.Nome LIKE '%$Busca%'
AND Disciplinas.Nome = '$Condicao';";
$this -> resultado = mysql_query($sql, $oConexao -> getConn());
}
In the search screen I'm doing the following test:
if (empty($_POST['chkDisciplina'])) {
$Busca = $_POST['txtbusca'];
$_POST['chkDisciplina'] = '1';
$oAluno = new alunosclass();
$oAluno -> listar($Busca);
}
else{
$Busca = $_POST['txtbusca'];
$arrayFiltro = $_POST['chkDisciplina'];
$separador = ' AND ';
$Condicao = implode( $separador, $arrayFiltro );
$oAluno = new alunosclass();
$oAluno -> buscaAvancada($Busca, $Condicao);
}
So now the problem is in the filter part, because if I just type a txt in the search with all checkboxes unchecked it works perfectly.
Would anyone have any ideas?