I'm trying to get a jQuery script to update the content of an HTML paragraph tag variously according to whether or not a PHP if statement, which checks for data in a database, evaluates to true or not:
if ($num_rows > 0) { ?> // If results are returned from database...
<script>
$(document).ready(function() {
$('p.message').text('Some data'); // ... p should read 'Some data'
});
</script>
<?php else { // otherwise
<script>
$(document).ready(function() {
$('p.message').text('No data'); // ...p should read 'No data'
});
</script>
}
The contents of are intended to change dynamically without the need for a page refresh, but do not do so. Only after the page has been refreshed is the new value shown.
Any ideas as always much appreciated.
if()at the time the php code is executed. if the variable changes later, the JS code for the OTHER condition will physically not be present in your page.