Note that there are some explanatory texts on larger screens.

plurals
  1. POSql UPDATE on link click
    primarykey
    data
    text
    <p>I'm trying to update a one value when a user clicks on a link.</p> <pre><code>&lt;?php $data = mysql_query("SELECT * FROM comments a LEFT JOIN pins b ON a.pin_id = b.id INNER JOIN board c on b.board_id = c.id WHERE a.to_id = '$myid' AND a.status = 'unviewed'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { Print "&lt;li&gt;"; Print "&lt;a href='/board/pins/".$info['board_id']."/".$info['pin_id']."'&gt;"; Print "&lt;img src='".$info['pin_url']."' width='50' align='left'&gt;"; Print "&lt;font size='1'&gt;comment received on ".$info['date']."&lt;/font&gt;&lt;/a&gt;"; Print "Collection: ".$info['board_name']."&lt;/li&gt;"; } ?&gt; </code></pre> <p>The link is the one above.</p> <p>how can I edit the above code to include an update query <code>"UPDATE comments SET status='viewed' WHERE to_id = '$myid' AND id='$postid'"</code> when the link is clicked?</p> <p>EDIT:</p> <p>this is my mark_viewed.php:</p> <pre><code>&lt;?php $con=mysqli_connect("XXX","XXX","XXX","XXX"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // get values sent from address bar $myid=$_GET['myid']; $postid=$_GET['postid']; mysqli_query($con,"UPDATE comments SET status='viewed' WHERE to_id ='$myid' AND id='$postid'"); mysqli_close($con); ?&gt; </code></pre> <p>And my the send page:</p> <pre><code>&lt;?php // display of the notifications dropdown menu $query_select = "SELECT * FROM comments a LEFT JOIN pins b ON a.pin_id = b.id LEFT JOIN board c on b.board_id = c.id WHERE a.to_id = '$myid' AND a.status = 'unviewed' ORDER BY a.date DESC"; $result_select = mysql_query($query_select) or die(mysql_error()); $rows = array(); while($row = mysql_fetch_array($result_select)) $rows[] = $row; foreach($rows as $row){ $myid = $row['user_id']; // my id $name = $row['board_name']; // collection name $boardid = $row['board_id']; // collection id $postid = $row['pin_id']; // post id $url = $row['pin_url']; // image url echo "&lt;li&gt;&lt;a href='/board/pins/$boardid/$postid' data-myid='$myid' data- postid='$postid' class='markviewed'&gt;"; echo "&lt;img src='$url' height='50' width='50'&gt;"; echo "New comment in $name."; echo "&lt;/a&gt;&lt;/li&gt;"; } ?&gt; </code></pre> <p>I have the JS in the head of the same page but it isn't working. The varibles are fine on this page <code>$myid</code> and <code>$postid</code> but they aren't being sent/received on mark_viewed.php</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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