0

I have a table like

<table width="60%" border="0">
    <tr>
        <td>intId</td>
        <td>tagname</td>
        <td>cid</td>
        <td>lid</td>
    </tr>
    <tr>
        <td>1</td>
        <td>chemis</td>
        <td>5</td>
        <td>0</td>
    </tr>
    <tr>
        <td>2</td>
        <td>hist</td>
        <td>4</td>
        <td>0</td>
    </tr>
    <tr>
        <td>3</td>
        <td>canada</td>
        <td>0</td>
        <td>9</td>
    </tr>
    <tr>
        <td>4</td>
        <td>chemis</td>
        <td>6</td>
        <td>0</td>
    </tr>
    <tr>
        <td>5</td>
        <td>chemis</td>
        <td>9</td>
        <td>2</td>
    </tr>
    <tr>
        <td>6</td>
        <td>hist</td>
        <td>3</td>
        <td>1</td>
    </tr>
</table>
$srarchkey_arr = array('chemis','tes','loyal','hist','canada');

My output should be

<table width="60%" border="0">
    <tr>
        <td>Tag Name </td>
        <td>cid</td>
        <td>lid</td>
    </tr>
    <tr>
        <td>Chemis</td>
        <td>5,6,9</td>
        <td>0,0,2</td>
    </tr>
    <tr>
        <td>hist</td>
        <td>4,3,</td>
        <td>0,1</td>
    </tr>
    <tr>
        <td>canada</td>
        <td>0</td>
        <td>9</td>
    </tr>
</table>

Please refer the fiddle

i.e In my tags table i have lots of tags with cid and lid

I want to search the words which are in array $srarchkey_arr. I want to search these tags and give the output as specified. I used the like query but it gives the out put as individual record. So i again use loops to concat the cid and lids.

Is this possible to do this with single query and loop. Is there any possibility to pass this like array or like in() for strings.

Please help me. thanks

2
  • 1
    It would be great if you could provide the part of your php code where you execute and handle the query, it is hard to help without knowing how you are doing this. Commented Dec 5, 2013 at 5:35
  • use group_concat function Commented Dec 5, 2013 at 5:43

1 Answer 1

1

use this sql

SELECT tagname, group_concat(cid), group_concat(lid) from test.check group by tagname;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.