Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You basically require two tables, with this structure</p> <p>table_categories</p> <pre><code>_____________________________ | id | title | -----------+---------------+ </code></pre> <p>table_category_detail</p> <pre><code>______________________________________________ | id | categoryId | articleId | -----------+---------------+------------------ </code></pre> <p>To extract all categories, select all from the <code>table_categories</code> and put up into the select menu with <code>mutiple</code> selection enabled.</p> <p>Next, when posted get the selected box values and insert into <code>table_category_detail</code> one by one</p> <p>This is how you create a select box</p> <pre><code>$query = "SELECT * FROM table_categories"; $result = mysql_query($query); echo '&lt;select multiple="multiple"&gt;'; while($row = mysql_fetch_assoc($result)) { echo '&lt;option value="'.$row['id'].'"&gt;'.$row['title'].'&lt;/option&gt;'; } echo "&lt;/select&gt;"; </code></pre> <p>Or a Multiple Check Box</p> <pre><code>while($row = mysql_fetch_assoc($result)) { echo '&lt;input type="checkbox" name="selcats[]" value="'.$row['id'].'"&gt; ' .$row['title']; } </code></pre> <p><strong>After the post:</strong></p> <pre><code> // Here write codes to insert the article first $articleId = mysql_insert_id(); //get the id $values = $_POST['selcats']; foreach($values as $value) { $query = "INSERT into `table_category_detail` VALUES(NULL, $value, $articleId)"; $result = mysql_query($result); } </code></pre>
 

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