Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the row id of html table
    primarykey
    data
    text
    <p>Assume I have some data from the database and store in a array, which like this:</p> <pre><code>$testArray = array( array('0', 'name1', 'status1'), array('1', 'name2', 'status2') ); </code></pre> <p>and I can print the content of the array as a html table, like this way:</p> <pre><code>Id name status 0 name1 status1 1 name2 status2 </code></pre> <p>I want to use a 'status' dropdown list at the end of each row to change the status of each entry, and update into the database table. My questions are: How do I get the row id of each row(the 'Id' column) when I select a option of the drodown list? How to pass these info to the backend inorder to update the database table? I guess it should use some javascript. And below is the code:</p> <pre><code>&lt;?php $testArray = array( array('0', 'name1', 'status1'), array('1', 'name2', 'status2') ); ?&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Id&lt;/td&gt; &lt;td&gt;name&lt;/td&gt; &lt;td&gt;status&lt;/td&gt; &lt;/tr&gt; &lt;?php for ($i = 0; $i &lt; count($testArray); $i++){ echo '&lt;tr&gt;'; for ($j = 0; $j &lt; count($testArray[$i]); $j++){ echo '&lt;td&gt;'; echo $testArray[$i][$j]; echo '&lt;/td&gt;'; } echo '&lt;td&gt;'; echo '&lt;select&gt;'; echo "'&lt;option value='0'&gt;status1&lt;/option&gt;"; echo "'&lt;option value='1'&gt;status2&lt;/option&gt;"; echo '&lt;/select&gt;'; echo '&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks for help!</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