One way to improve the organization of a procedural project is to separate the php from the html and break the code (noodles) into functions. Also remember to use modern api's for database connection by avoiding the mysql functions _ *
Example:
macarrao.php
<?php
$qr = "SELECT historico.*, funcionarios.nome FROM historico
INNER JOIN funcionarios
ON (historico.funcionario_id = funcionarios.funcionario_id)";
$resultado = mysql_query($qr);
?>
<table>
<tr>
<td>Nome</td>
<td>Matricula</td>
<td>Data entrada</td>
<td>Data saida</td>
</tr>
<?php
while($row = mysql_fetch_assoc($resultado)){
echo
'<tr>
<td>'. $row['nome'] .'</td>
<td>'. $row['matricula'] .'</td>
<td>'. $row['entrada'] .'</td>
<td>'. $row['saida'] .'</td>
</tr>';
?>
</table>
1 - Remove the code of the start and while of macarrao.php and create a new file that can be sql / oficials.php, it will look like this:
include 'conexao.php';
function getHistorio($conexao){
$sql = 'SELECT historico.*, funcionarios.nome FROM historico
INNER JOIN funcionarios
ON (historico.funcionario_id = funcionarios.funcionario_id)';
$query = mysql_query($sql, $conexao) or die(mysql_error());
$historicos = array();
while($row = mysql_fetch_assoc($query)){
$historicos[] = $row;
}
return $historicos;
}
//outras funções....
2 - Copy the html content of the pasta.php to a new file, view / historical_list.php which will only have a foreach to list the historics
<?php
include 'sql/funcionario.php';
$historico = getHistorio($conexao);
?>
<table>
<tr>
<td>Nome</td>
<td>Matricula</td>
<td>Data entrada</td>
<td>Data saida</td>
</tr>
<?php foreah($historico as $item){ ?>
<tr>
<td><?php echo $item['nome']; ?></td>
<td><?php echo $item['matricula']; ?></td>
<td><?php echo $item['entrada']; ?></td>
<td><?php echo $item['saida']; ?></td>
</tr>
<?php } ?>
Recommended reading:
Flat PHP vs Symfony
Why should not we use functions of type mysql_ *?
MySQL vs PDO - Which is the most recommended to use?