Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate database after user action
    primarykey
    data
    text
    <p>Ok, so I am relatively new to php, javascript, and jquery. Here is what I have going.</p> <p>I have a table that is created when the page opens that is filled up using a for from a database query (just a simple <code>select *</code>). The problem right now is the final <code>&lt;td&gt;</code> is a dropdown menu that the use can change (changing the item from viewed to unviewed and back). So, what i want to do is when the user selects either value in the drop down menu, i want to get the second column value (the ID value in my database) of that row and update the viewed status. My problem is I am not sure how to use JQuery to get the ID value into my update statement for the database. Here is what I have so far:</p> <pre><code>&lt;script language="Javascript"&gt; //cache the select and span elements var table = document.getElementById('leads'); var mySelect = document.getElementById("mySelect"); //when it changes mySelect.onchange = function() { var row = this.parentNode.parentNode; //change the tag innerHTML checking the selected value of the select if (mySelect == "1") { var id = table.rows[row.rowIndex].cells[1].innerHTML; //HOW DO I GET THIS ID INTO A SELECT STATEMENT THAT CAN EXECUTED BY A PHP FUNCTION } } &lt;/script&gt; </code></pre> <p>EDIT: Here is an attempt so far... Inside my if statement I added the following line:</p> <pre><code>$.get("updateToNew.php", {lid: id}); </code></pre> <p>and here is the php (you can assume the connection to the database and everything is correct inside this file):</p> <pre><code>$query = mysql_query("UPDATE myTable SET new=1 WHERE ID=".$_GET['lid']) or die(mysql_error()); </code></pre> <p>This does not throw any errors, but does not update the database. Also, I noticed as I was troubleshooting that the script only runs the first time the drop down menu is changed, any time after that it does nothing.</p>
    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.
 

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