hi ,

I want to split the field by comma and that should check the values in another table and display multiple values as given below.

Here is my table format:

Table1:
======

id : nos

1 12,13,14
2 14
3 14,12

Table2:
=======

id : values

12 PHP
13 JAVA
14 C++

Now , I want output like this:
=============================


1 PHP, JAVA, C++
2 C++
3 C++, PHP

How to fetch this using mysql query?

Thanks in advance.

- Gnaniyar Zubair

What you want to do is:

$query = "SELECT id,nos FROM Table1";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
    echo $row['id'];
    $values = split(",",$row['nos']);
    $first_entry = true;
    foreach ($values as $one_nos)
    {
        $query2 = "SELECT values FROM Table2 WHERE id = '" . $one_nos . "'";
        $result2 = mysql_query($query2);
        $row2 = mysql_fetch_array($result2);
        if ($first_entry == true)
        {
            echo $row2['values'];
        }
        else
        {
            echo "," . $row2['values'];
        }
    }
    echo "<br />";
}

I'm pretty sure that should return the correct result for you.

hi,
I'm also having the same problem but the difference is i need to display in asp .net
Pls help me on this

Table1:
======

id : nos

1 12,13,14
2 14
3 14,12

Table2:
=======

id : values

12 PHP
13 JAVA
14 C++

Now , I want output like this:
=============================


1 PHP, JAVA, C++
2 C++
3 C++, PHP


thanks in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.