Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code below demonstrates how to:</p> <ol> <li>Query your database</li> <li>Display it's output in a table with checkboxes beside each entry</li> <li>Submit selected checkboxes to a page</li> <li>Display selection when page reloads</li> </ol> <p>Beware of some parameters that you may need to modify, e.g. database name, username, password, name of the primary key ("id").</p> <p> <pre><code># connect to mysql $db_link = mysql_connect('localhost', 'root', ''); if (!$db_link) die('Cannot connect : ' . mysql_error()); # select database $db_selected = mysql_select_db('test_db', $db_link); if (!$db_selected) die ('Cannot select database : ' . mysql_error()); # execute search query $sql = 'SELECT * FROM `test_table` LIMIT 20'; $result = mysql_query($sql); # check result if (!$result) die('Could not successfully run query: ' . mysql_error()); # display returned data if (mysql_num_rows($result) &gt; 0) { ?&gt; &lt;form action="" method="post"&gt; &lt;table style="border: 1px solid black"&gt; &lt;?php while ($row = mysql_fetch_assoc($result)) { echo '&lt;tr&gt;&lt;td&gt;'; echo '&lt;input type="checkbox" name="selected[]" value="'.$row['id'].'"/&gt;'; echo '&lt;/td&gt;'; foreach ($row as $key =&gt; $value) echo '&lt;td&gt;'.htmlspecialchars($value).'&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; &lt;/table&gt; &lt;input type="submit"/&gt; &lt;/form&gt; &lt;?php } else echo '&lt;p&gt;No data&lt;/p&gt;'; # free resources mysql_free_result($result); # display posted data echo '&lt;pre&gt;'; print_r($_POST); echo '&lt;/pre&gt;'; ?&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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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