Forum Moderators: coopster

Message Too Old, No Replies

multiple rows => 1 row?

         

ktsirig

10:53 am on Dec 30, 2005 (gmt 0)

10+ Year Member



Hi all and Merry Christmas!

I wanted to ask how would I deal with the following problem:

Say I have a table [TABLE1]:
customeridname
1nick
2george
3harry

and a [TABLE2]:
numbercar
1Lotus
2BMW
2FERRARI
2LADA
3Lamporgini

If I want to see george's car, I would write: SELECT car from TABLE2 where number ='2';
and I would get :
BWM
FERRARI
LADA

The thing is that I don't want to get 3 lines, but just one, where each record will be separated e.g. by TAB.
But with mysql_fetch_array I will get 3 lines. I must somehow "check" for each person if he has more than one cars,
and show them in one row, not in multiple rows.

I am stuck!

jatar_k

3:20 pm on Dec 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can loop through all of the results and then concatenate them into a single string using a tab. If you use a loop then it could loop once or many times, it wouldn't matter.