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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:51:49+00:00 2026-06-15T20:51:49+00:00

Hi there i’ve 2 fields in a mysql database with similar content: Field 1

  • 0

Hi there i’ve 2 fields in a mysql database with similar content:

Field 1: a>b>c
Field 2: 1>2>3

I wish to put them in different rows, exploded.

Example:

-----------------
|Field 1|Field 2|      
|----------------
|a      |1      |
|b      |2      |
|c      |3      |

Here a snippet for the code that should make the work:

$result = mysql_query($insert_cat);
while ($row = mysql_fetch_assoc($result))
{
    //assegno variabili per l'array associativo
    $idcat = $row["id_categorie"];
    $descat = $row["categoria"];

    //inizio a ciclare all'interno degli array per ricavare le categorie
    $ar_id=explode('>',$idcat);
    $ar_des=explode('>',$descat);

    foreach($ar_id as $value_id)
    {

        foreach($ar_des as $value_des)
        {

        }

        echo $value_id.'|'.$value_des."\n";
    }
}

The problem is: how can I (for testing) echoing what should be inserted in the table?
I’ve tried but with no luck.

  • 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-15T20:51:50+00:00Added an answer on June 15, 2026 at 8:51 pm

    Have you tried using the array_combine function – see the php docs on the subject.

    This will merge two arrays, with the first as they keys for the second. As a result you can replace your foreach loops with something like this

    $fullArray = array_combine($ar_id, $ar_des);
    foreach($fullArray as $key_id => $val_des)
    {
        echo $key_id . " | " . $val_des;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There was a similar question posted asking in general about alternatives to Qt. Well,
There is a website called Gild.com that has different coding puzzles/challenges for users to
There are a lot of example implementations of daemons on the net. Most that
There are 3 different ways to get data out of a BLOB column from
I've tracked down a weird MySQL problem to the two different ways I was
There are 2 different article types: post(blog) and page in Octopress. What if I
Let's say I'm outputting a post title and in our database, it's Hello Y’all
There are a lot of questions about full-joining in mysql(5.1.36). Of course the solution
There are some stdlib functions that throw errors on invalid input. For example: Prelude>

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.