Difficulty in While Loops and Foreach

Asked

Viewed 114 times

0

I’ve been studying php for a little while so I didn’t properly understand the structure of the loops as while and foreach I would like someone to explain to me why this while displays nothing, and when I try to use error foreach. Thanks in advance for understanding and patience.

<div id="resultado">
  <table width="100%">
    <thead>
      <tr align="center">
        <th align="center"class="filter-match" data-placeholder="">ID|</th>

        <th align="center"class="filter-match" data-placeholder="">|Cliente|</th>

        <th align="center"class="filter-match" data-placeholder="">|Data Retorno|</th>

        <th align="center" data-placeholder="">|Nome do Contato|</th>  

        <th height="24" data-placeholder="">|Assunto</th>

        </tr>
      </thead>
      </div>

<tbody>



  <tr align="center" >
<?php 


    $acompanhamento = mysql_query("SELECT id_cliente, cliente_nome, data_ret, nome, mensagem FROM acompanhamento 
    WHERE data_ret = '".date('Y-m-d')."' ");
   while ($exibe = mysql_fetch_array($acompanhamento)){
       echo
                           $exibe["id_cliente"];
                            $exibe["nome"];
                            $exibe["mensagem"];
                            $exibe["cliente_nome"];
                            $exibe["data_ret"];

   };


    echo   $id_cliente;    
           $cliente_nome; 
           $data_ret;      
           $nome;          
           $mensagem;  






    ?>  


    </tr>
  </tbody>

</table>



//--------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------

<div id="resultado">
 <table width="100%">
    <thead>
      <tr align="center">
        <th align="center"class="filter-match" data-placeholder="">ID|</th>

    <th align="center"class="filter-match" data-placeholder="">|Cliente|</th>

    <th align="center"class="filter-match" data-placeholder="">|Data Retorno|</th>

    <th align="center" data-placeholder="">|Nome do Contato|</th>  

    <th height="24" data-placeholder="">|Assunto</th>

    </tr>
  </thead>
  </div>

<tbody>



  <tr align="center" >
<?php 


    $acompanhamento = mysql_query("SELECT id_cliente, cliente_nome, data_ret, nome, mensagem FROM acompanhamento 
    WHERE data_ret = '".date('Y-m-d')."' ");
   $exibe = mysql_fetch_array($acompanhamento)
   foreach mysql_fetch_array($acompanhamento) as $value)
            {
       echo
                           $exibe["id_cliente"];
                            $exibe["nome"];
                            $exibe["mensagem"];
                            $exibe["cliente_nome"];
                            $exibe["data_ret"];

   };


    echo   $id_cliente;    
           $cliente_nome; 
           $data_ret;      
           $nome;          
           $mensagem;  






    ?>  


    </tr>
  </tbody>

</table>
  • Before using the looping gives a var_dump(mysql_fetch_array($accompaniment));

  • If you returned something in the query it will display. Remember that the mysql_* functions were discontinued in the current php version

1 answer

0

1º Check if you made the connection with the bank correctly

2º Use simple quotes $displays['id_client']; $displays['name']; $displays['message']; $displays['cliente_name']; $displays['data_ret'];

3º place any echo inside the repeater to be able to know if it is performing as it should, maybe it is not even entering the while.

4º You made 1 Echo and used point and comma after each $displays, it is only necessary ; in the last variable.

  • The likely reason for a Foreach error is because your $tracking variable should not be receiving anything.

Browser other questions tagged

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