Get only one value from mysqli_fetch_assoc [closed]

1

I'm trying to make a code for stock control using PHP. Each time the user uses the program, the program must select an employee and from there select the rest of the fields as needed.

This part of the code works perfectly:

        <tr>
            <td><?php echo $row[funcionario] ?></td>
            <td><?php echo $row[origem] ?></td>
            <td><?php echo $row[destino] ?></td>
            <td><?php echo $row[quantidade] ?></td>
            <td><?php echo $row[package] ?></td>
            <td><?php echo $row[conteudo] ?></td>
            <td><?php echo $row[sabor] ?></td>
            <td><b><a onclick="excluiProduto(<?php echo $row[id_saida] ?>)" class="btn btn-sm btn-danger" id="deleta"><span class="glyphicon glyphicon-trash" aria-hidden="true"><span></a></td></b>
        </tr>
<?php


    }
    $func = $row[funcionario];
    echo $func;
?>
</table>
</div>

<div class="container">
    <div style="padding-top: 20px" class=" center-block" >
        <form method="GET" action="imprimirRel.php">
        <button value="<?php echo $func ?>" type="submit" name="submit" class="btn btn-sm btn-info" style="<?php echo $mostraTabela ?>">Confirmar saída</button>
        </form>


    </div>
</div>

Now I'm trying to get this value and move to another page in order to print a report with the following code:

<?php

    INCLUDE "conexao.php";

  $func = $_GET['submit'];
  echo $func; die;



    $sql = "SELECT * FROM controle_saida WHERE DATE(data_saida)=CURDATE() AND funcionario='".$func."'";
    //DATE(date)=CURDATE()
    $result = mysqli_query($conexao, $sql);

    if (mysqli_num_rows($result)==0){
        $mostraTabela = "display:none";
    }
    else {
        $mostraTabela = "";
    }


    ?>

The problem is that I can not get this employee by the value of submit, since this is outside of mysqli_fetch_assoc. If I put in, it pulls all the values that will appear inside the while loop. I imagine you're not doing it the best, is there any other way to do it? Remembering that the employee does not need to be inside the loop, since with each use all the lines will have only one employee, but the other fields will change.

MODIFIED: The code I'm doing is for output control. In it I have the register below:

AsIcompletetheregistrationandclickonadd,Iaddinthelistbelow:

The problem is: Let's imagine that we are doing the registration of the 3rd employee, and using only this code:

$sql = "SELECT * FROM controle_saida WHERE DATE(data_saida)=CURDATE()";
It will not be enough to bring the table just from one employee, and will eventually bring in all the records that were made today, inclusive of the other 2 employees. What I want is: I am filling Eduardo's product register, I want to just name him on the next page to print a report, and I can not do that.

    
asked by anonymous 17.10.2015 / 20:32

2 answers

3

Felipe, let me get this straight.

  • Create a column in your table controle_saida with name eg: id_funcionario
  • When doing "Add" pass the value of the id of the employee of the table where the employees are that I believe to be another for this new column id_funcionario .
  • When you query the controle_saida table, do the following:
  • .

    $sql = "SELECT * FROM controle_saida WHERE DATE(data_saida)=CURDATE() AND id_funcionario = '".$func["id"]."'";
    
        
    17.10.2015 / 20:49
    1

    Create a button of type hidden and put the value in it:

        <form method="GET" action="imprimirRel.php">
              <input type="hidden" value="<?php echo $func; ?>" name="submit"/>
              <button type="submit" class="btn btn-sm btn-info" style="<?php echo $mostraTabela ?>">Confirmar saída</button>
        </form>
    
      

    Note: The $ func variable must contain the value you want to pass

        
    17.10.2015 / 20:46