Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate a new id for row in database?
    primarykey
    data
    text
    <p>I am using jQuery draggable, when the draggable element moves I save those css values (left, top) into the database ($wpdb) using ajax... I have no problem when there is one draggable element it runs smooth... but adding onto the project I want to add multiple draggable elements and thats where I am having a problem... here is the code I am sending the data to the database...</p> <pre><code> global $wpdb; //The data here comes from an ajax call $_POST['x']; $_POST['y']; $_POST['id']; $term_id = 100; $name = $_POST['id']; $slug = $_POST['x']; $term_group = $_POST['y']; if(isset($_POST['id'],$_POST['y'], $_POST['x'])){ print_r($_POST); } //Im adding into wp_terms a default table (for testing)... $query = "INSERT INTO $wpdb-&gt;terms (term_id, name, slug, term_group) VALUES (%s, %s, %s, %s)"; //Here I insert the ajax data into the columns $wpdb-&gt;query($wpdb-&gt;prepare($query, $term_id, $name, $slug, $term_group)); $wpdb-&gt;update("$wpdb-&gt;terms", array('slug' =&gt; $_POST['x'], 'term_group' =&gt; $_POST['y']), array('name' =&gt; $_POST['id'])); die(); </code></pre> <p>This code summed up: It connects to the $wpdb then I take the data from the ajax call and store them in a variable.. I am targeting the wp_terms table... So on draggable element <code>stop</code> the ajax data is sent to my script and stored in the database, on <code>update</code> every time draggable stops I preserve that row and only update the <code>x</code> and <code>y</code> values located in <code>slug</code> &amp;&amp; <code>term_group</code> that has the <code>name</code> of <code>$_POST['id']</code>... this updates it well, but since <code>$term_id = 100</code> a static value, I cannot create a new row for an element with a new <code>$_POST['id']</code>.. does that make sense.. its much more simple than I think I made it out to be... I am trying to do what I am already doing but when there is a new <code>$_POST['id']</code> I need to generate a <code>$term_id = 101</code> dynamically it works exactally how I want if I manually give the row a term_id of 101... </p> <p>Table looks like this...</p> <p><img src="https://i.stack.imgur.com/dU7WP.jpg" alt="table"></p> <p>Im trying to add a 101 and silly2.. then 102 silly3.. something like that, then when the last two values x &amp; y change the 152 &amp; 32 changes but term_id 101 stays and silly 2 stays... </p> <p><img src="https://i.stack.imgur.com/vHymo.jpg" alt="enter image description here"></p> <p>The thing here is I dont want to create a new instance of silly, silly2, silly3... I want to overwrite the last two columns..</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