I am making a web-app that has flagging in it. I've got that working, however, it doesn't maintain through a refresh (which happens every 20 seconds or so). How do I make it maintain through a refresh.

Here's a stripped-down version of my code:
HTML Code:
<html>
<head>
<script type="text/JavaScript">
function load() {
  window.setTimeout('window.location="display.php"; ',<?php echo $u['refresh']; ?>+"000");
}
function flag(id,btn) {
var divid = id;
var abtn = btn;
  document.getElementById(divid).style.background="#F0D7D7 url('display-bg-flagged.png') repeat-x";
  document.getElementById(btn).href="javascript:unflag('"+divid+"','"+abtn+"')";
  document.cookie = 'flag'+divid+'=true; expires=; path=/';
}
function unflag(id,btn) {
var divid = id;
var abtn = btn;
  document.getElementById(divid).style.background="#F0F0F0 url('display-bg.png') repeat-x";
  document.getElementById(btn).href="javascript:flag('"+divid+"','"+abtn+"')";
  createCookie("flag"+id,"",-1);
}
</script>
</head>
<body onLoad='load()'>
<?php
$user = $_COOKIE["logged-in"];
$posts = $u['posts'];

  $result = mysql_query("select * from visitordata where user='".$_COOKIE['logged-in']."' order by id desc limit $posts");
  //the while loop
  $id=$_GET['id']; 

  echo "<div id=\"feedback\">";

  while($r=mysql_fetch_array($result))
  {
    echo "<div class=\"post\" id=\"".$r['id']."\" name=\"flag\" style=\"background:#F0F0F0 url(display-bg-flagged.png) repeat-x;\">";
    echo "<div class=\"info\"><a href=\"delete.php?delid=".$r['id']."\" title=\"Delete Feedback\"><img src=\"delete.png\" border=\"0\"></a> ";
    echo "<a href=\"javascript:flag('".$r['id']."','flagbtn".$r['id']."');\" title=\"Flag Feedback\" id=\"flagbtn".$r['id']."\"><img src=\"flag.png\" border=\"0\"></a>";
    echo " | <div class=\"time\">".$r['time']."</div> | <div class=\"name\">".$r['name']."</div> | <div class=\"location\">".$r['location']."</div> | <a href=\"http://".$r['ip_address']."\">".$r['ip_address']."</a></div>";
    echo "<a href=\"mail.php?mailid=".$r['id']."\" title=\"Email Feedback\"><img src=\"email.png\" border=\"0\"></a> <a href=\"block.php?ip=".$r['ip_address']."&user=".$_COOKIE['logged-in']."\"><img src=\"block.png\" border=0></a> | <div class=\"message\">".$r["message"]."</div></div></div>";
  }

  echo "</div>";
?>
</body>
</html>
the variables like $r['xxxxx'] get info from a MySQL database.