Take only one value from mysqli_fetch_assoc

Asked

Viewed 175 times

1

I’m trying to make a code for inventory control using PHP. Each time the user uses the program, the user 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 take 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 am not able to catch this employee by the value of Submit, since this is outside the 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 right way, is there any other way? Remembering that the employee does not need to be inside the loop, since at each use all lines will have only one employee, but the other fields change.


MODIFIED: The code I am doing is for product output control. In it I have the registration below: Cadastro de produtos

As I complete the registration and click add, I add in the list below: Lista de produtos

The problem is: Let’s imagine that we are registering the 3rd employee, and using only this code:

$sql = "SELECT * FROM controle_saida WHERE DATE(data_saida)=CURDATE()";

It won’t be enough to bring in just one employee table, and it will eventually bring in all the records that were made today, including the other 2 employees. With this what I want is: I’m filling out Eduardo’s product registration, I just want to call his name on the next page to print out a report, and I’m not able to do it.

  • I don’t understand.. Does each employee have to have a button on it? And then fill it in

  • In fact, you select an employee and from that fill out the rest of the report. It is a product output control, IE, as a page for printing will come out, it is not convenient to be done with multiple employees at the same time.

  • $func = $Row[run]; echo $func; it prints the desired value ?

  • This works, but as I am dealing with a table, it will bring all the values of the table once it is inside the while. Even if it was only an employee, Felipe for example, in echo would bring "Felipe Felipe Felipe Felipe"

  • And what is the value you want, I’m sorry but I still don’t understand?

  • The right thing would be to explain what makes this system of yours, or how you want it to work, and only then could you expose the problem.

  • I thought I had explained enough. I’ve already edited my question.

Show 2 more comments

2 answers

3


Felipe, let me get this straight.

  1. Create a column in your table controle_saida ex-name.: id_funcionario
  2. When performing "Add" pass the value of id of the official table where are the employees I believe to be another for this new column id_funcionario.
  3. When you make the query in the table controle_saida, do so:

.

$sql = "SELECT * FROM controle_saida WHERE DATE(data_saida)=CURDATE() AND id_funcionario = '".$func["id"]."'";
  • This works, but as I am dealing with a table, it will bring all the values of the table once it is inside the while. Even if it was only an employee, Felipe for example, in echo would bring "Felipe Felipe Felipe Felipe"

  • So, can you give us the rest of the code that comes before? So I can see where and how you’re getting the value <td><?php echo $row[funcionario] ?></td>.........

  • I will modify the question since I could not make it clear.

  • I changed my answer...

  • Thyago, I think that was what was missing, create another table for employees. I’m beginner and still have trouble making a correct MER. I will try and put here the answer, but I will give you the correct answer, because I believe you are right. Thank you

  • Great, I’m happy with that... When you want to know a little more about what you want to do, search for "Relationship Tables", in this case we are doing a "gambiarra" with relationship manually, see relationship options 1:1 - 1:N - N:N Hugs!

Show 1 more comment

1

Create a Hidden button 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 variable $func must contain the value you want to pass

  • Hiago, I guess I couldn’t explain it properly. I would not like to have a button for each employee, but rather select an employee and from there fill out the rest of the report. Think that I’m trying to create an output control, and as there will be a printed signature page from each employee confirming the products that are coming out, it doesn’t suit that it be done with more employees at the same time. It became clearer?

  • Yes, I’m sorry I’ll review and modify the answer

  • I modified the question, if the $func variable has the desired value it will be correctly passed the value to the printRel.php

  • I edited my question. You think it’s clearer?

  • Yes he did, but @Thiago has already given him the solution.

Browser other questions tagged

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