-2
I have two tables, table A with id and tasks (description), and another table B with a task fk, quantity, fk run. In addition to other columns that are not relevant.
In my table in html (table), I show all the tasks already in thead, and in the results I get the respective amounts of each task.
The problem is that a store can register 5 tasks, and register activities for its employees, but after a while, it can register one more task, only qd this occurs, my view of the table in html breaks. Because in my table B there is no data of this new task.
Would anyone have any suggestions how to solve this problem?
Part of the search query of the amount of tasks:
//tabela A, checo todas as tarefas cadastradas
$consulta2 = $pdo->prepare("SELECT id_tarefa FROM tarefa WHERE id_loja=:id");
$consulta2->bindParam(':id', $id_loja, PDO::PARAM_INT);
if($consulta2->execute()){
if($consulta2->rowCount() > 0){
while($dados_cons2 = $consulta2->fetch(PDO::FETCH_OBJ)){
$id_tarefa2=$dados_cons2->id_tarefa;
//essa seria minha tabela B, checo todas as atividades, que possuem as quantidades da tarefas
$dados3 = $pdo->prepare("SELECT * FROM atividades_diarias as ativ where ativ.id_ativ=:id_ativ and ativ.id_loja=:id_loja and ativ.tipo_atividade=:tipo and ativ.id_tarefa=:id_taf");
$dados3->bindParam(':id_ativ',$id_ativ, PDO::PARAM_INT);
$dados3->bindParam(':id_loja',$id_loja, PDO::PARAM_INT);
$dados3->bindParam(':tipo',$tipo_atividade, PDO::PARAM_STR);
$dados3->bindParam(':id_taf',$id_tarefa2, PDO::PARAM_INT);
$dados3->execute();
while($table3 = $dados3->fetch(PDO::FETCH_OBJ)){
$qtd_tarefa = $table3->qtd_tarefa;
//só que as tarefas novas n tem dados antigos na minha tabela B, ele é inexistente, aí quebra a tabela
if($qtd_tarefa!=null){ //usei null mas n funcionou
echo'<td>'.$qtd_tarefa.'</td>';
}else{
$vazio="";
echo'<td>'.$vazio.'</td>';
}
}
My table in Html (example)
Date.... Job name...task1.... task2... NEWJOB..... time of entry
1/6/18............ Isadora.............................. 3....................... 08:00
Result I need:
Date.... Job name...task1.... task2... NEWJOB..... time of entry
1/6/18............ Isadora........................... 2................................................ 08:00
Note that the new registered task takes the value of the next column, qd should empty, since there is no historical data about it.
Does anyone know how to check if my task exists in table B, and if n exists put null in the table view in html? I have tried several alternatives including, Inner Join.
Thank you!
When you search the qtd_task column comes as null when you have no task?
– L.J
No. Qd use var_dump, it appears only the values of the tasks that exist in table B.
– Isadora Almeida
I put an example of how is appearing in html and how I need q to appear.
– Isadora Almeida
Try to put instead of empty ="" put empty="test" to see how it appears.
– L.J
I did, but he never showed. It only shows what is in table B. And it makes sense because my new task ID (table A) does not exist in table B. But I can’t see how to treat it. I think qd arrives in select as the job id of the store does not exist it nor continues.
– Isadora Almeida
Perhaps an Inner Join of table A with table B. It will only return the records that exist in the two tables.
– L.J
Yes, I’ve tried too and it wasn’t. Because it only takes what’s in both, as you said.
– Isadora Almeida
I’ll try with left and right Join to see.
– Isadora Almeida
Also n worked.
– Isadora Almeida