显示所有孩子的最爱

I have this two tables..

table 1 "kids"

enter image description here

table 2 "favorites"

enter image description here

What I want is to display it in the table like this..

enter image description here

how can I do that?

this is the code i tried..`

        $result = mysql_query("SELECT kids.*, favorites.* from kids INNER JOIN favorites ON kids.kids=favorites.kids");
       $number='1';if (mysql_num_rows($result) > 0) {
      while($row = mysql_fetch_array($result))
        {

          $idnumber=$row['kids'];

          ?>

          <td class="centered"><?php echo $number;?></td>

          <td class="centered hidden"><?php echo $idnumber;?></td>

          <td class="centered hidden"><?php echo $row['favorites'];?></td>

          <?php



      }
      ++$number;

    }

  ?>

`

SELECT kids.kids, favorites.favorites FROM kids INNER JOIN favorites ON kids.kids=favorites.kids;

Is an example, but I suggest you to look more into SQL joins.

TRY:

SELECT a.int,a.kids,b.kids,GROUP_CONCAT(b.favourite) from kids a, favourites b where a.kids = b.kids

This should work

This is what you want-

SELECT a.int as int, a.kids as Kids, GROUP_CONCAT(b.favourite separator ',') as Favourites 
FROM kids a, favourites b WHERE a.kids = b.kids

Try:

SELECT
  kids.int as '#', kids.kids as 'Kids',
  GROUP_CONCAT(favorites.favr) as 'Favourites'
FROM kids
  JOIN favorites on kids.kids = favorites.kids
GROUP BY favorites.kids