How to list values from multiple queries in a single table?

0

I have a table with the attendant, total / day and total / month columns.

I typed tr / td the names of people through the first MYSQL query. I need through the second query to add the records of these people and print in the next td. The problem is that the queries are from different tables and I do not know how I can do to print inside a tr through the While query values of different MYSQL tables.

$nome = $_SESSION['usuarioNome'];
$nomes = mysql_query("SELECT nome FROM usuarios"); //primeira consulta
$consulta = mysql_query("SELECT COUNT(*) FROM atendimento WHERE nome = '$nome' AND DAY(data)=DAY(NOW())"); // segunda consulta

Follow the HTML:

            <table style="text-align: center;width: 100%;" class="table table-striped table-bordered" id="table_id">
            <thead>
                <tr style="background-color: #007bff;">

                  <td style="width: 5%;color: white;font-size: 16px;">Atendente:</td>
                  <td style="width: 4%;color: white;font-size: 16px;">Total/Dia:</td>
                  <td style="width: 4%;color: white;font-size: 16px;">Total/Mês:</td>

                </tr>
            </thead>
              <tbody>

                <?php  while($prod = mysql_fetch_array($nomes)) { ?>

                  <tr data-id="<?php echo $prod['id'] ?>">
                    <td style="width: 5%;color: black;font-size: 16px;"><?php echo $prod['nome'] ?></td>
                    <td style="width: 5%;color: black;font-size: 16px;"><?php  ?></td>
                    <td style="width: 5%;color: black;font-size: 16px;"><?php  ?></td>
                  </tr>

                <?php } ?>

              </tbody>
        </table>

    
asked by anonymous 28.11.2018 / 18:15

1 answer

0

And if we join queries would not it be better?

It would look something like this:

SELECT 
    nome,
    (SELECT COUNT(*) FROM ATENDIMENTO WHERE NOME = '$nome' AND DAY(data)=DAY(NOW())) AS TOTAL_DIA
FROM USUARIOS

In this way you can iterate normally:

<?php  while($prod = mysql_fetch_array($nomes)) { ?>
  <tr data-id="<?php echo $prod['id'] ?>">
    <td style="width: 5%;color: black;font-size: 16px;"><?php echo $prod['nome'] ?></td>
    <td style="width: 5%;color: black;font-size: 16px;"><?php echo $prod['TOTAL_DIA'] ?></td>
    <td style="width: 5%;color: black;font-size: 16px;"><?php  ?></td>
  </tr>
<?php } ?>
    
28.11.2018 / 18:33