-1
Guys I have a problem in my php, I want to select the name of people according to a code and for this I made an IF, but the code that should take the values of the database and print on the page is repeating a command before printing the next value. I appreciate anyone who can help me.
Code:
PHP - Query:
<?php include("config.php");
$consulta1 = $MySQLi -> query("SELECT * FROM TB_HOSPITAIS");
$consulta2 = $MySQLi -> query("SELECT * FROM TB_MEDICOS
join TB_PLANTOES on MED_PLANT_CODIGO = PLANT_CODIGO
join TB_HORARIOS on PLANT_HOR_CODIGO = HOR_CODIGO");
?>
Table - Showing the values:
<table class="table table-striped" border="2" align="center text-center">
<tr>
<th scope="col">#</th>
<th scope="col">Medico(a)</th>
<th scope="col">Horário</th>
</tr>
<?php while($resultado2 = $consulta2 -> fetch_assoc()) {?>
<tr>
<th scope="row">Domingo</th>
<td>
<?php if ($resultado2['MED_PLANT_CODIGO'] == 1)
echo $resultado2['MED_NOME']; ?>
</td>
<td> <?php echo $resultado2['HOR_HORARIO']; ?> </td>
</tr>
<tr>
<th scope="row">Segunda</th>
<td>
<?php if ($resultado2['MED_PLANT_CODIGO'] == 2)
echo $resultado2['MED_NOME']; ?>
</td>
<td> <?php echo $resultado2['HOR_HORARIO']; ?> </td>
</tr>
<?php } ?>
</table>
Config.php:
<?php
session_start();
$endereco = "localhost";
$usuario = "root";
$senha = "";
$banco = "DB_SCH";
$MySQLi = new mysqli($endereco, $usuario, $senha, $banco, 3306);
if(mysqli_connect_errno()){
die(mysqli_connect_error());
exit();
}
mysqli_set_charset($MySQLi,"utf8");
function br_us($data) {
$data = implode("-",array_reverse(explode("/",$data)));
return $data;
}
function us_br($data) {
$data = implode("/",array_reverse(explode("-",$data)));
return $data;
}
?>
In the table instead of printing the name of the doctor on duty 1 on Sunday and then the name of the doctor on duty 2 on Monday, he first prints Monday as empty, generates a new table and prints the value of Monday and leaves Sunday empty.
Could you explain to me how to leave the days of the week fixed in the <td> and then the code that corresponded to that day, would appear there? Because my idea was Friday, Saturday and Sunday to receive 2 names in the same <td> and is being created a new <td> for the second name.
– eu.eu
@I couldn’t quite understand what you want to do, but it seems to me it would be a new question. it would also be important to add examples of database records, which is expected to be returned by query and what/how should be presented.
– tvdias