how it returns an array of a function

Asked

Viewed 38 times

-1

I want to take data from a SELECT array

public function aluno($cod)
{
    $cod = "";
    global $pdo;
    $sql = $pdo->prepare("SELECT 
    KS0042.CODALUNO, ks0300.ALUNO 
    From KS0042
    Inner Join KS0300 ON KS0300.CODALUNO = KS0042.CODALUNO And KS0300.CODENTIDADE = 
    KS0042.CODENTIDADE 
    Inner Join KS0100 ON KS0100.CODCADASTRO = KS0042.CODCADASTRO And KS0100.CODENTIDADE = 
    KS0042.CODENTIDADE
    Where KS0042.CODCADASTRO = :c");
    $sql->bindValue(":c",$cod);
    $sql->execute();
    $dado = $sql->fetchAll();
    return $dado;
    }

I want to use the data in this block of code, but I can’t return the $given array:

   $u->conectar("KSSOFTNOVO","localhost","root","");

  if ($msgErro == "") {
     $u->aluno($cod);
  }
 }
  ?>

   <div class="center"> 

    <h5 id="aluno">Selecione o aluno:</h5>
    <form method="post">

    <select name="nome" id="nome">
    <?php 
      if (count($dado)) {
        foreach ($dado as $dados) {

          
       
    ?>
    <option value="<?php echo $dados['CODALUNO']?>"><?php echo $dados['ALUNO'] ?></option>
    <?php
        }
      }

      
     
      ?>
   </select>
  

1 answer

1

Within the function aluno($cod) you are setting the variable $cod to an empty value:

public function aluno($cod)
{
    $cod = "";
...

This is probably the reason you’re not returning anything, because you’re not finding any students with code = "". Try removing this line from the function.

Browser other questions tagged

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