diff vote.inc.php @ 221:2b39068c4968

Tiny bit of work on voting code.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 18 Nov 2013 02:00:32 +0200
parents a14663f6497d
children 1bb4f4bcb027
line wrap: on
line diff
--- a/vote.inc.php	Mon Nov 18 01:27:52 2013 +0200
+++ b/vote.inc.php	Mon Nov 18 02:00:32 2013 +0200
@@ -50,15 +50,14 @@
 
   // Try fetching previously stored votes
   $sql = stPrepareSQL(
-    "SELECT * FROM votes WHERE voter_id=%d",
+    "SELECT entry_id,value FROM votes WHERE voter_id=%d",
     stGetSessionItem("voter_id"));
 
+  $votes = array();
   if (($res = stExecSQL($sql)) !== false)
   {
     foreach ($res as $vote)
-    {
-      stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
-    }
+      $votes[$vote["entry_id"]] = $vote["value"];
   }
 
   // Output voting system HTML
@@ -99,12 +98,13 @@
       ($compo["showAuthors"] ? "   <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
       "   ";
 
+      $val = isset($votes[$eid]) ? $votes[$eid] : 0;
+
       for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
       {
-        $name = "entry".$eid;
         echo
           "<td class=\"vvalue\">".
-          stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), "").
+          stGetFormRadioButtonInput("entry".$eid, "", "", $i, ($i == $val), "").
           "</td>";
       }