I have a query that seems to fail about one out of five times, resulting in a completely blank page. Here's the query and the call to it (which appears before any HTML is displayed):
$query = "SELECT msg.id, msg.to, msg.from, msg.subject, msg.date,
u1.first_name as to_first, u1.last_name as to_last,
u2.first_name as from_first, u2.last_name as from_last
FROM messages msg, userprofiles u1, userprofiles u2
WHERE msg.read = 'n' AND u1.id = msg.to
AND u2.id = msg.from AND msg.to = '$userid'
ORDER BY msg.date DESC";
$reslt_message = mysql_query($query, $conn) or die(mysql_error());
If there is anything wrong with this query, please let me know. Otherwise, assuming that the query is ok, would it be wrong (or even work at all) to put a header inside the "die" that reloads the page, or would that be bad practice?
I can see the possibility of getting an infinite loop, but that could be remedied by adding a variable to the end of the header that would force the code to reload only if it hasn't reloaded yet... if that is clear.
When the page crashes, refreshing it works. If I click the link to this page 10 times, it could be the 1st or 10th time that results in a crash, so I'm thinking that the query is ok but it is having trouble processing it or something, which is what led me to think about reloading the page.
Any thoughts?