Since this is a JavaScript function, you just place the function itself inside the header, and then in PHP, you output the call to the function in your if like this:
if ($num!=0) {
echo '<script type="text/javascript">show_confirm();</script>';
} else {
//irrelevant code
}
PHP is a server-side scripting language, while JavaScript is client-side. You can't call the JavaScript function directly from the server-side like you were trying to do. You can however output javascript to the page via PHP as I have done in my example.