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 6719357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:05:00+00:00 2026-05-26T09:05:00+00:00

I have a mysql db with an article (article_id, keyword) db table where keywords

  • 0

I have a mysql db with an article (article_id, keyword) db table where keywords is a comma-separated list. I have created two new empty tables:

keywords (keyword_id, keyword) where each row has only one keyword.

article_key (article_id, keyword_id) where each row has only one keyword.

Thus I want to have a many-to-many relationship from articles to keywords. I wanted to create a short script to extract the id and keywords from the original article table, split the keywords and populate the two new tables appropriately. I assumed this would be easy, but has proved a little more tricky than I thought.

Any help would be much appreciated.

  • 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-05-26T09:05:00+00:00Added an answer on May 26, 2026 at 9:05 am

    You could do something similar to this:

    //Get articles with keywords:
    $result = mysql_query("SELECT article_id, keyword FROM article");
    
    //Cycle through all articles
    while ($article = mysql_fetch_assoc($result)) {
         $article_id = $article['article_id'];
         $keywords = $article['keyword'];
         //Explode keywords on seperator (; in this case)
         $keyword_array = explode(";", $keywords);
    
         //For each keyword get the corresponding ID
         for ($i = 0; $i < count($keyword_array); i++) {
              $result2 = mysql_query("SELECT keyword_id FROM keywords WHERE keyword = '" . $keyword_array[$i] . "'");
              //Get keyword_id
              $row = mysql_fetch_assoc($result2);
              $keyword_id = $row['keyword_id'];
    
              //Insert new key
              mysql_query("INSERT INTO article_key VALUES (" . $article_id . ", " . $keyword_id . ")");
         }
    }
    

    In this script (not tested) I assumed you already have your keywords table filled with the keywords, and that your article table contains a comma seperated list of KEYWORDS and NOT id’s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two mysql tables, one listing article names, the other listing the authors
I have a MySQL database table that contains an Article ID ( primary key
I have three mysql tables, first holds information about articles (Article ID, author ID,
I have two tables from two different databases. For example: Table: Articles1 - Database:
In my table I have two fields among others : article_id and version Example:
I have two tables with these structure: articles: article_id, text tags: tag_id, article_id, text
Lets say I have a table in MySQL called articles, that has a column
I have mysql table that has a column that stores xml as a string.
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a set of tables in MySQL like this (foreign keys referenced by

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.