Note that there are some explanatory texts on larger screens.

plurals
  1. POMarking memos as read
    primarykey
    data
    text
    <p>I am putting together a site that handles H&amp;S memos, and I need members to confirm that they have read their memos. I have looked at ways of handling this and they are based on assuming that members have read the memos the last time they logged on. I can't use this method as I need to assure their company that their workers have read their safety memos.</p> <p>I have tried various ways of doing this but none are working well enough.</p> <p>The main problem is selecting the correct ID number for the memo that they have clicked that they have read and then updating the details to the <code>memo_read</code> table. Any pointers, workarounds or solutions much appreciated.</p> <p>This is what I have so far:</p> <pre><code>&lt;?php $user_id = $user_data['user_id'] ; $company_id = $user_data['company']; $nothing = ''; $result1 = mysql_query ("SELECT `user`, `memo_id` FROM`memo_read` WHERE `user`= '$user_id '") or die(mysql_error()); $memo_id_query = ''; while($row = mysql_fetch_array($result1)){ $memo_id_query .= " AND `id`!= '".$row['memo_id']."'"; } ?&gt; &lt;div id="memo"&gt; &lt;h7&gt;These are your unread memos!&lt;/h7&gt; &lt;table class="bit"&gt; &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Author&lt;/th&gt;&lt;th&gt;Time/Date&lt;/th&gt;&lt;th&gt;Memo&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;?php $result = mysql_query ("SELECT `id`, `memos`, `author`, `time`, `title` FROM `memo` WHERE `worker`= 1 AND `company`='$company_id' ".$memo_id_query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $id = $row['id']; $memo = $row['memos']; $author = $row['author']; $time = $row['time']; $title = $row['title']; global $id; ?&gt; &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;?php echo $title; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $author; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $time;?&gt;&lt;/td&gt; &lt;td id="mem"&gt;&lt;a class="toggle" href="#.bit" &gt;read/hide&lt;/a&gt; &lt;div class="hiddenDiv" &gt;&lt;?php echo $memo; ?&gt;&lt;br&gt; &lt;form id="tickmemo" action="" method="post"&gt; &lt;input type="submit" name="submit" value="mark as read"&gt; &lt;/form&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tbody&gt; &lt;?php } if (empty($_POST['submit']) === false) { $q=("INSERT INTO `memo_read` VALUES ('$nothing', '$user_id', '$id') "); $result = mysql_query($q) or die(mysql_error()); } ?&gt;&lt;/table&gt;&lt;/div&gt; </code></pre> <p>(edit) This is working great now i'll put it up here if anyone else needs it or if you can suggest any tweeks!</p> <pre><code>&lt;?php $user_id = $user_data['user_id'] ; $company_id = $user_data['company']; $nothing = ''; $result1 = mysql_query ("SELECT `user`, `memo_id` FROM`memo_read` WHERE `user`= '$user_id '") or die(mysql_error()); $memo_id_query = ''; while($row = mysql_fetch_array($result1)){ $memo_id_query .= " AND `id`!= '".$row['memo_id']."'"; } if (isset($_GET['success']) &amp;&amp; empty($_GET['success'])) { echo 'You have marked that memo as read!&lt;br&gt;We will send you back in 3 seconds!'; header("Refresh: 3; url=\"http://www.testbed1.tk/login/index.php\""); } else { ?&gt; &lt;div id="memo"&gt; &lt;h7&gt;These are your unread memos!&lt;/h7&gt; &lt;table class="bit"&gt; &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Author&lt;/th&gt;&lt;th&gt;Time/Date&lt;/th&gt;&lt;th&gt;Memo&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;?php $result = mysql_query ("SELECT `id`, `memos`, `author`, `time`, `title` FROM `memo` WHERE `worker`= 1 AND `company`= '$company_id' ".$memo_id_query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $id = $row['id']; $memo = $row['memos']; $author = $row['author']; $time = $row['time']; $title = $row['title']; ?&gt; &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;?php echo $title; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $author; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $time;?&gt;&lt;/td&gt; &lt;td id="mem"&gt;&lt;a class="toggle" href="#.bit" &gt;read/hide&lt;/a&gt; &lt;div class="hiddenDiv" &gt;&lt;?php echo $memo; ?&gt;&lt;br&gt; &lt;form id="tickmemo" action="#" method="post"&gt; &lt;input type="hidden" name="id" value="&lt;?php echo $id;?&gt;" /&gt; &lt;input type="submit" name="submit" value="mark as read"&gt; &lt;/form&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tbody&gt; &lt;?php } $id = $_POST['id']; if (empty($_POST['id']) === false) { $q=("INSERT INTO `memo_read` VALUES (''".mysql_real_escape_string($nothing)."'','".mysql_real_escape_string($user_id)."','".mysql_real_escape_string($id)."') "); $result = mysql_query($q) or die(mysql_error()); header('Location: worker.php?success'); } ?&gt;&lt;/table&gt;&lt;/div&gt; &lt;?php } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload