Note that there are some explanatory texts on larger screens.

plurals
  1. POEDIT: add an identifier to a dynamically generated row
    primarykey
    data
    text
    <p>I'm pulling down two tables from the db. There's a Javascript function that adds a row from <code>Table2</code> into the <code>Table1</code>. What i've been trying to do is get the data from <code>Table1</code> on the <code>confirm_trade.php</code> page so I can put it into the db but can't figure out how to pull that row(<code>item_id</code>). I thought putting the table in a form would allow me to access them through the <code>$_POST</code> but that's not working. How to add an identifier to the jquery row so I can grab on the <code>confirm</code> page?</p> <p>The appended rows coming from the jQuery function are the rows I need the item_id from.</p> <pre><code>function addto(obj) { var $row = $(obj).parents("tr"); var $table = $("#tradee"); var item_id = $row.find(".item-id").text(); var item_name = $row.find(".item-name").text(); var item_desc = $row.find(".item-desc").text(); var newTR = $("&lt;tr&gt;&lt;td&gt;"+item_id+"&lt;/td&gt;&lt;td&gt;"+item_name+ "&lt;/td&gt;&lt;td&gt;"+item_desc+"&lt;/td&gt;&lt;/tr&gt;"); $table.append(newTR); } </code></pre> <p>Table2:</p> <pre><code> &lt;div id='fixedDiv'&gt; &lt;form action="confirm.php" method="post"&gt; &lt;table align="center" id="Table2"&gt; &lt;tr&gt;&lt;td&gt;Other Item&lt;/td&gt;&lt;/tr&gt; &lt;?php while($rowi =$item-&gt;fetch_assoc()) {?&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo $rowi['item_id']; ?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo $rowi['item_name']; ?&gt; &lt;/td&gt; &lt;td&gt;&lt;?php echo $rowi['item_description'];?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" name="submit" value="Continue"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; &lt;br&gt; </code></pre> <p>Table 1:</p> <pre><code> &lt;table align="center" id="Table1"&gt; &lt;tr&gt;&lt;th&gt;item_id&lt;/th&gt; &lt;th&gt;Cat_id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;/tr&gt; &lt;?php while($row =$item_results-&gt;fetch_assoc()) {?&gt; &lt;tr&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td class="item-id"&gt; &lt;?php echo $row['item_id']; ?&gt; &lt;/td&gt; &lt;td&gt;&lt;?php echo $cat_id = $row['cat_id']; ?&gt; &lt;/td&gt; &lt;td class="item-name"&gt;&lt;?php echo $item_id = $row['item_name'];?&gt;&lt;/td&gt; &lt;td class="item-desc"&gt;&lt;?php echo $item_descrip = $row['item_description'];?&gt; &lt;/td&gt; &lt;td&gt;&lt;input type="button" class="added" onclick="addto(this)" value="Add" /&gt; &lt;td&gt;&lt;input type="button" class="removed" onclick="remove()" value="Remove" &gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; </code></pre>
    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