0
I am putting together a list that collects user data. As some data is in different tables (attachments, precisely) I have put together a query select to capture only those attachments having the same id
user (table I called attach_user_id
previously fed by the form) and played in a variable to be able to print from inside the loop that makes the query in the students table. The script does exactly what I want, or rather almost. The list is printed, formatted, everything ok But the page is cut and the script does not pass the last row of the table, IE, nor load the footer. I can’t understand where I’m going wrong, and the script returns no error.
Where am I going wrong?
<?php // o erro esta daqui em diante
while($user = mysqli_fetch_array($users) or die(mysqli_error($sql_con)))
{
$user_id = $user['id'];
$user_attachments = mysqli_query($sql_con,"SELECT attach_name,attach_path,attach_user_id FROM " . ATTACHMENTS_TABLE . " WHERE attach_user_id LIKE '$user_id'") or die(mysqli_error($sql_con));
$docs = mysqli_fetch_array($user_attachments);
?><tr>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['nome'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['dia'] . " de " . str_replace_assoc($mes,$user['mes']) . " de " . $user['ano']; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['curso'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['unidade'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['endereco'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['bairro'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['cep'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['numero'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['rg'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['cpf'] . " " ; ?></font></td>
<td align='center'><font face='Calibri' size='2' color='#888888'><a href='<?php echo $docs['attach_path'] . $docs['attach_name']; ?>'><img src='doc.png' alt='Ver documento anexado' style='width:16px;height:20px;'></a></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['email'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['telefone'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['celular'] . " "; ?></font></td>
<td><font face='Calibri' size='2' color='#888888'><?php echo $user['site'] . " "; ?></font></td>
</tr><!-- a pagina so e impressa ate exatamente neste ponto -->
<?php } ?>
</table>
<hr />
<script type="text/javascript">
function voltar()
{
location.href="form.php"
}
function lista()
{
location.href="lista.php"
}
</script>
<p align="center"><button onclick="lista()">Recarregar lista</button> <button onclick="voltar()">Novo cadastro</button></p>
<br/><br/>
<?php INCLUDE('./footer.php'); ?>
The line
hr
is printed?– MagicHat
It is not no, it is only printed until immediately reach the last tag of the while, I commented there in the code
– Nando Correa
it returns only a single user, or loops with several users, and where did you indicate after listing everything?? And what do you have before the while?? Ja thought about trying to solve this with a single query using Inner Join, or Left Join in SQL instead of looping with other queries just to get 1 single data from another table??
– Fernando VR
This is the weirdest thing, he even makes the loop, lists all the entries as expected, points out where the files are but does not load the footer, not even the other html tags after the loop.. I’m sure the fault is inside the loop because it started only after I decided to put the attachments in the register.. before the while only has the table html header and the other strings of the querys referring to the tables of students and attachments, there in the while only has the query that unites the data of these queries
– Nando Correa
tries to take out the
die(mysqli_error($sql_con)
of your code, and see if you still don’t get the ending. Maybe the script may be having an error at the end of the look, and the die may be finishing but without showing the error on the screen. The scheme is you go debugging line by line until you find the error. By the part of the code q vc posted, apparently there is no error. Have q check the q selects are returning, to see if there is no empty line coming, q may be returning the error within the loop.– Fernando VR
... and check if the option to show both php and mysql errors is enabled...
– MagicHat
Magichat, are active, at least I’ve had several mistakes since the beginning of creating this site.
– Nando Correa
Fernando VR, I removed the die() and checked the loop with an if. You got it right, it solved the problem. If I had known that this was so, I would not have warmed my head so much, since I planned to do this as soon as I solved the problem. Thank you all very much!
– Nando Correa