The problem is that you are only rendering either div with your PHP if statement. Since your page is loaded only once, only the div meeting the if condition will be rendered into the DOM (web page). Therefore you cannot hide/show the divs, since there will be only one to hide/show.
This answer is not the optimal solution, but will work for what you are looking for. That being said, you could do the following:
Load both divs, with the return condition from your PHP advertise function being what hides/shows the divs.
//$result is either true or false
$result = advertise($clmn['id'],$clmn['uid']);
echo '<div id="num1"' . ($result ? 'hidden':'' ) . '>this should be replace</div>';
echo '<div id="num0"'. (!$result ? 'hidden':'' ) . '>this is normal</div>';
The above echo statements echo the output of both divs, while hidding one and showing the other based on the return value of the advertise function. Note that you can reverse the output of the echo statements by switching around the $result
variable to !$result
(negation) in the echo statements.
That way, both divs will be loaded into the page, and you will be able to use the script:
$('#somediv').click(function(){
$( "#num0" ).fadeOut( "slow", function() {
$( "#num1" ).fadeIn( "slow");
});
});
I hope this answers your question.
Cheers!