Using Javascript alert in the middle of PHP code

Alternative 1:
The good thing about alternative 1 is that you can use the actual php variables directly in Javascript code
[code lang="php"]
<?php
$counter = 123;
//PHP Code
print '<script type="text/javascript">'; //Php writing javascript code ...
print 'alert("' . $counter . ' files were coppied")'; //Php writing javascript code ...
print '</script>'; //Php writing javascript code ...
//PHP Code Continues
?>
[/code]

Alternative 2:
[code lang="php"]
<?php
$counter = 0;
// php code
if( $counter = 0 ) )
{
?>
<script >
alert('Problem occured during uploading ...')
</script>
<?php
}
//Some more php code
?>
[/code]