That is a very good point (one that I regularly make myself๐ )
Instead of 'or die', set a var to reflect the fact that an error occured.
Then at the end of your script, you can check to see wether any errors occured, and if there were errors, you can trash the output that was generated up to now, and replace it with a clean error message;
if (!mysql_query())
{
$bAnErrorOccured = TRUE;
$aErrorMessages[] = 'Query error'.mysql-error();
}
else
{
// Process data
}
// end of script, check for errors
if ($bAnErrorOccured == true)
{
// Errors have occured, print the messages
ob_end_clean();
echo '<pre>';
print_r($aErrorMessages);
echo '</pre>';
}
else
{
// No errors, print the page.
ob_end_flush();
}