Problem for displaying the values of an Array on the front end

Asked

Viewed 46 times

1

Guys, good night. It is difficult to display the values of an array on the front end. In the backend it appears but on the front it does not.

My service task class where is the function that returns the array:

 public function procurar(){

       global $procura;

       $comando = $this->conexao->prepare("select tarefa, id_status from tb_tarefas where tarefa like :nome");
       $comando->bindValue(':nome', "%{$procura}%");
       $comando->execute();

       $inf = $comando->fetchAll(PDO::FETCH_OBJ);

       print_r($inf);

   }

Here is the part of the code responsible for giving command in the bank in the task class :

elseif($acao == 'procurar'){

        $tarefa = new Tarefa();

        $conexao = new Conexao();

        $procura = isset($_POST['procura']) ? $_POST['procura'] : "";

        $tarefaService = new TarefaService($conexao, $tarefa);
        $retorno = $tarefaService->procurar();

        header('location: buscar_tarefas.php?resultado=1');
    }

And then there at the front-end I opened the php block and had written the $return variable. I also gave a require Once to call the task classController:

<?php
 global $retorno;

print_r($retorno);
?>

Help me please, guys

2 answers

1


What happens is that you are not returning any value in the search function, so the value of $return is as null.

To solve this, you must change print_r($inf); for return $inf;

Check out the documentation!

  • I did what you said but it still wasn’t. Could you take a look at the project ? If this isn’t too uncomfortable for you, follow the link on github. The project is in two repositories. github.com/gabrieltec97/Projeto-Help-Desk.git github.com/gabrieltec97/app_lista_tarefas.git

  • In your code you’re still print_r($inf);, switch to Return $inf and try again. Commit too.

  • And on your Github also I couldn’t find where you want to display the result

  • It’s busy there, brother. I want to show there in the file search tasks where I left a comment there. I’m trying to implement a search on that system, now just need to display on screen. Take a look there please

  • Remove the header('location: buscar_tarefas.php?resultado=1'); taskController.php:141

  • so brother, if I remove it, it will not display on that page. I want the content to be displayed on this page called lookup

  • Friend, this is not how you pass data through php pages. The header just redirects, and from what I’ve seen you don’t need it because the.php query has a require of it. Remove and make the "query" through the page search_tasks.php, it would look like this: search_tasks.php? acao=search

  • Po I’m not understanding the way you’re talking bro, you can change the code there on github and save, if you can’t, you can give me the code here?

  • I told you, just remove the header(); and make the request by the url search_tasks instead of doing it in taskController

  • It worked, brother. Thank you so much for your help and patience in helping me. Thanks a lot! tmj

Show 5 more comments

0

If the information process is not done on the same page where you want to print the result, you need to transfer the return from one page to another.

Just like the @PauloVictor said, you need a return in office first.

public function procurar(){

    global $procura;

    $comando = $this->conexao->prepare("select tarefa, id_status from tb_tarefas where tarefa like :nome");
    $comando->bindValue(':nome', "%{$procura}%");
    $comando->execute();

    $inf = $comando->fetchAll(PDO::FETCH_OBJ);

    return $inf;

}

After having this return, and if the data is processed on the same page that will be displayed the front, just give a print_r()which will be printed, otherwise use session, for example, to pass the information to another page.

  • I did what you said, but it still wasn’t. Could you take a look at the project ? If this isn’t too uncomfortable for you, follow the link on github. The project is in two repositories. https://github.com/gabrieltec97/Projeto-Help-Desk.git https://github.com/gabrieltec97/app_lista_tarefas.git

Browser other questions tagged

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