advice on refreshing incoming messages with mt_rand()?
<p>is this a good way of doing it? or should i use a date time stamp with seconds rather?</p>

<p>while i am on a page, the new message must come through without me refreshing the page</p>

<p>my code is written in php:</p>

<pre><code>&lt;div id='div_longgray_gradient2'&gt;
&lt;div id='div_float_img'&gt;
&lt;table width='96%' border='0'&gt;
&lt;tr&gt;
    &lt;td rowspan='2' width='40px' align='left'&gt;

        &lt;img src='/images/rainbow/arrow.png'&gt;
    &lt;/td&gt;

    &lt;td align='left'&gt;
        &lt;span class='spn_big_black_rbc'&gt;MESSAGES&lt;/span&gt;
    &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
    &lt;td align='left'&gt;
        &lt;span class='spn_med_lightblue_rbc'&gt;Inbox&lt;/span&gt;    
    &lt;/td&gt;
    &lt;td align='left'&gt;
    &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br/&gt;
&lt;br/&gt;

&lt;table width='80%' align='center'&gt;
&lt;tr&gt;
    &lt;td class='td_show_contact_heading' align='left'&gt;&lt;span class='spn_med_lightblue_rbc'&gt;Received&lt;/span&gt;&lt;/td&gt;
    &lt;td class='td_show_contact_heading' align='left'&gt;&lt;span class='spn_med_lightblue_rbc'&gt;Message&lt;/span&gt;&lt;/td&gt;
    &lt;td class='td_show_contact_heading' align='left'&gt;&lt;span class='spn_med_lightblue_rbc'&gt;From&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php 
$cursor = $pager-&gt;getFirstIndice(); 
foreach ($pager-&gt;getResults() as $msg)
{ 
$has_freechat = false;  
//changed id to withid here
$freechat_req_link="profiles/confirmfreechat?withid=".$msg-&gt;getRcProfileTableRelatedByProfileIdFrom()-&gt;getId();
$freechat_req_link=link_to('Freechat',$freechat_req_link,'class=link_small_dark');

$cc = sizeof ($fc_records);
for($i = 0; $i &lt; $cc; $i++) 
{
    if($fc_records[$i]-&gt;getProfileIdWith() == $msg-&gt;getProfileIdFrom())
    {       
        $has_freechat = true;       
        break;
    }
}   

$unique_code_from = $msg-&gt;getRcProfileTableRelatedByProfileIdFrom()-&gt;getUniqueCode();
$block_url = link_to('Block User',"blocklist/block?unqiue_code=$unique_code_from",'class=link_medium_blue');
echo "&lt;tr&gt;";
$date = add_date($msg-&gt;getCreatedAt(),$hr=2);
echo "&lt;td class='td_show_contact_item' align='left'&gt;".$date."&lt;/td&gt;";
$opened_once = $msg-&gt;getOpenedOnce();
if($opened_once &gt;= 1)
{
   echo "&lt;td class='td_show_contact_item' align='left'&gt;".link_to($msg-&gt;getSubject(),   'messagebox/read?cursor='.$cursor,'class=link_medium_blue')."&lt;/td&gt;";
}    
else
{ ?&gt;
   &lt;td align='left'&gt;
     &lt;a href="&lt;?php echo url_for('messagebox/read?cursor=').$cursor ?&gt;" style='color:#ff0000 !important' class='spn_small_red_rbc'&gt;&lt;?php echo $msg-&gt;getSubject();?&gt;&lt;/a&gt;        
   &lt;/td&gt;      
&lt;?php 
} 
echo "&lt;td class='td_show_contact_item' align='left'&gt;".$unique_code_from." ( $block_url )&lt;/td&gt;";
echo "&lt;/tr&gt;";
++$cursor; 
}

function add_date($givendate,$hr=2)
{
$cd = strtotime($givendate);
$newdate = date('Y-m-d H:i:s', mktime(date('h',$cd)+$hr, date('i',$cd), date('s',$cd), date('m',$cd), date('d',$cd), date('Y',$cd)));
return $newdate;
}
?&gt;
&lt;/table&gt;
&lt;br/&gt;
Displaying results &lt;?php echo $pager-&gt;getFirstIndice() ?&gt; to  &lt;?php echo $pager-&gt;getLastIndice() ?&gt;.
&lt;br/&gt;

&lt;?php if ($pager-&gt;haveToPaginate()): ?&gt;

&lt;?php echo link_to('&amp;laquo;', 'messagebox/list?page='.$pager-&gt;getFirstPage()) ?&gt;
&lt;?php echo link_to('&amp;lt;', 'messagebox/list?page='.$pager-&gt;getPreviousPage()) ?&gt;
&lt;?php $links = $pager-&gt;getLinks(); foreach ($links as $page): ?&gt;
&lt;?php echo ($page == $pager-&gt;getPage()) ? $page : link_to($page, 'messagebox/list?page='.$page) ?&gt;
&lt;?php if ($page != $pager-&gt;getCurrentMaxLink()): ?&gt; - &lt;?php endif ?&gt;
&lt;?php endforeach ?&gt;
&lt;?php echo link_to('&amp;gt;', 'messagebox/list?page='.$pager-&gt;getNextPage()) ?&gt;
&lt;?php echo link_to('&amp;raquo;', 'messagebox/list?page='.$pager-&gt;getLastPage()) ?&gt;
&lt;?php endif ?&gt;

&lt;table width='96%' border='0'&gt;
&lt;tr&gt; 
    &lt;td rowspan='2' width='40px' align='left'&gt; 
        &lt;img src='/images/rainbow/arrow.png'&gt; 
    &lt;/td&gt; 
    &lt;td align='left'&gt; 
        &lt;span class='spn_big_black_rbc'&gt;&lt;/span&gt; 
    &lt;/td&gt; 
&lt;/tr&gt; 
&lt;tr&gt;
    &lt;td align='left'&gt;
        &lt;span class='spn_med_lightblue_rbc'&gt;Sent Items&lt;/span&gt;   
    &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;table width='80%' align='center'&gt;
&lt;tr&gt;
    &lt;td class='td_show_contact_heading' align='left'&gt;&lt;span class='spn_med_lightblue_rbc'&gt;Sent&lt;/span&gt;&lt;/td&gt;
    &lt;td class='td_show_contact_heading' align='left'&gt;&lt;span class='spn_med_lightblue_rbc'&gt;Message&lt;/span&gt;&lt;/td&gt;
    &lt;td class='td_show_contact_heading' align='left'&gt;&lt;span class='spn_med_lightblue_rbc'&gt;To&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php
$cursor2 = $pager2-&gt;getFirstIndice(); 
$br = sizeof ($block_records);
foreach ($pager2-&gt;getResults() as $item)
{ 
    $link = link_to('Delete',"messagebox/deleteSentmsg?mid=".$item-&gt;getId(),'class=link_medium_blue');
    $id = $item-&gt;getRcProfileTableRelatedByProfileIdTo()-&gt;getId();    
    ?&gt;
    &lt;tr&gt;
        &lt;td class='td_show_contact_item' width='15%' align='left'&gt;&lt;?php echo $date = add_date($item-&gt;getCreatedAt(),$hr=2); ?&gt;&lt;/td&gt;
        &lt;td class='td_show_contact_item' width='45%' align='left'&gt;&lt;?php echo $item-&gt;getMessage()?&gt;&lt;/td&gt;
        &lt;td class='td_show_contact_item' width='25%' align='left'&gt;&lt;?php echo $item-&gt;getRcProfileTableRelatedByProfileIdTo()-&gt;getUniqueCode()."  ".$link;?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php
     ++$cursor2;    
}
?&gt;
&lt;/table&gt;
&lt;br/&gt;
Displaying results &lt;?php echo $pager2-&gt;getFirstIndice(); ?&gt; to  &lt;?php echo $pager2-&gt;getLastIndice(); ?&gt;.
&lt;br/&gt;
&lt;?php if ($pager2-&gt;haveToPaginate()): ?&gt;
&lt;?php echo link_to('&amp;laquo;', 'messagebox/list?page2='.$pager2-&gt;getFirstPage(),'class=link_big_dark') ?&gt;
&lt;?php echo link_to('&amp;lt;', 'messagebox/list?page2='.$pager2-&gt;getPreviousPage(),'class=link_big_dark') ?&gt;
&lt;?php $links = $pager2-&gt;getLinks(); foreach ($links as $page2): ?&gt;
&lt;?php echo ($page2 == $pager2-&gt;getPage()) ? $page2 : link_to($page2, 'messagebox/list?page2='.$page2,'class=link_big_dark') ?&gt;
&lt;?php if ($page2 != $pager2-&gt;getCurrentMaxLink()): ?&gt; - &lt;?php endif ?&gt;
&lt;?php endforeach ?&gt;
&lt;?php echo link_to('&amp;gt;', 'messagebox/list?page2='.$pager2-&gt;getNextPage(),'class=link_big_dark') ?&gt;
&lt;?php echo link_to('&amp;raquo;', 'messagebox/list?page2='.$pager2-&gt;getLastPage(),'class=link_big_dark') ?&gt;
&lt;?php endif ?&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>can anyone give some advise please?
i have no ajax/JS here so dont know how i would incorporate it</p>
