Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7727679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:31:12+00:00 2026-06-01T05:31:12+00:00

I have a problem inserting values on my table. ——————————————– | products_id | related_products_ids

  • 0

I have a problem inserting values on my table.

--------------------------------------------
|   products_id   |   related_products_ids |
| -----------------------------------------
|                |   1,2,3,4,6,            |
| -----------------------------------------
|    2            |   1,2,3,6,             |
| -----------------------------------------
|    3            |   1,2,4,               |
-------------------------------------------

There is a blank products_id value where all inserted values on each product ids are on its related_products_ids value.

I use this code,

for ($i=0; $i<count($_POST['rp_product']);$i++) {
    $check_val .= $_POST['rp_product'][$i];
    $check_val .=","; 
}

$insert_rp_ids1 = explode(',', $check_val);

foreach($insert_rp_ids1 as $rp_ids) {

    $related_query = "SELECT related_products_ids, products_id 
                      FROM ".TABLE_RELATED_PRODUCTS." 
                      WHERE products_id = '" . $rp_ids ."'";

    $result_rp = mysql_query($related_query);
    $related_products_value = mysql_fetch_assoc($result_rp);

    if(mysql_num_rows(mysql_query("SELECT products_id FROM ".TABLE_RELATED_PRODUCTS." WHERE products_id = '$rp_ids'"))){

        $rp_values = $related_products_value['related_products_ids'].$products_id.',';
        $rps_each1 = array('related_products_ids' => $rp_values);

        $wpdb->update( TABLE_RELATED_PRODUCTS, $rps_each1, array( 'products_id' => $rp_ids ));

     } else {

         $rps_each2 = array('products_id' => $rp_ids,
                   'related_products_ids' => $products_id.',');

         $wpdb->insert(TABLE_RELATED_PRODUCTS, $rps_each2);
     }
 }

Is there something wrong with my code? I can’t find it. That row is not necessary and its no use.

Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:31:13+00:00Added an answer on June 1, 2026 at 5:31 am

    That was a mess but this should avoid problems in future..

    for ($i=0; $i<count($_POST['rp_product']); $i++)
    {
      $check_val1 .= $_POST['rp_product'][$i] .","; //gather data
    }
    $check_val = trim($check_val1, ',');  //clean last ,
    unset($check_val1); //flush
    
    $insert_rp_ids1 = explode(',', $check_val);
    
    foreach($insert_rp_ids1 as $rp_ids)
    {
    
     if($result_rp = mysql_query("SELECT related_products_ids, products_id FROM ".TABLE_RELATED_PRODUCTS." where products_id = '" . $rp_ids ."'"))
     {
        if($products_id > 0)
       {
      $related_products_value = mysql_fetch_assoc($result_rp);
      $rp_values = $related_products_value['related_products_ids'] . "," . $products_id;
    
      $rps_each1 = array('related_products_ids' => $rp_values);
      $wpdb->update( TABLE_RELATED_PRODUCTS, $rps_each1, array( 'products_id' => $rp_ids ));
       }
      }
      else
      {
       if($rp_ids > 0 && $products_id > 0)
       {
       $rps_each2 = array('products_id' => $rp_ids, 'related_products_ids' => $products_id);
       $wpdb->insert(TABLE_RELATED_PRODUCTS, $rps_each2);
       }
      }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem about inserting values into the table with sqlite. supposing the
I have a problem with inserting a TextBox value into a SqlServer table. I
I have a problem in php code inserting values into database (I use PHPMyAdmin).
i have a problem in inserting the listbox value into mysql database in vb
i have a problem in inserting the listbox value into mysql database in vb
i have a problem in inserting some data into a table. I have done
I have a problem with inserting data into SQLite database using QSqlTableModel. The table
I am having problem with inserting string values (user_name, password) into a table, named
I'm having a strange problem in that I have php inserting text into a
i have problem with autorotate on iphone i set up in all classes -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.