How update this mysql_num_rows jquery without refresh page?

PHP Code:
<?php  
$count1_online 
$mysqli->query("SELECT * FROM `messages`"); 
$online1_count $count1_online->num_rows;           
?> 

<font size="3" color="orange"><?php echo $online1_count?> messages</font>
or

PHP Code:
<?php
$count1_online 
$mysqli->query("SELECT COUNT(*) AS message_count FROM `messages`");
$result $count1_online->fetch_assoc();
header('Content-Type: application/json');
echo 
json_encode($result);