Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting array data to mysql table
    primarykey
    data
    text
    <p>Basically i wanted this on my table,</p> <pre><code>-------------------------------------------- | products_id | related_products_ids | | ------------------------------------------ | 1 | 2 | | ------------------------------------------ | 1 | 3 | | ------------------------------------------ | 1 | 4 | -------------------------------------------- </code></pre> <p>I have checkboxes,</p> <pre><code>&lt;input value="1" type="checkbox" name="rp_product[]" id="in-category1"&gt; Microsoft IntelliMouse Pro 1 &lt;input value="2" type="checkbox" name="rp_product[]" id="in-category2"&gt; Microsoft IntelliMouse Pro 2 &lt;input value="3" type="checkbox" name="rp_product[]" id="in-category3"&gt; Microsoft IntelliMouse Pro 3 &lt;input value="3" type="checkbox" name="rp_product[]" id="in-category3"&gt; Microsoft IntelliMouse Pro 4 </code></pre> <p>What i wanted is to insert checked checkboxes into the table by <code>products_id</code>.</p> <p>I use this php code,</p> <pre><code>for ($i=0; $i&lt;count($_POST['rp_product']); $i++) { $check_val1 .= $_POST['rp_product'][$i] .","; } $check_val = trim($check_val1, ','); unset($check_val1); $insert_rp_ids1 = explode(',', $check_val); for($i=0;$i&lt;count($insert_rp_ids1);$i++) { $usetag = mysql_real_escape_string(stripslashes(ltrim(rtrim($insert_rp_ids1[$i])))); if($usetag == "") continue; $array1 = array('products_id' =&gt; (int)$products_id, 'related_products_ids' =&gt; $usetag); $wpdb-&gt;insert(TABLE_RELATED_PRODUCTS, $array1); } } </code></pre> <p>The problem is that, only the first checked checkbox is only inserted. What seems to be the problem or do you have other solution? Please help.</p>
    singulars
    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