SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    output mutiple rows with a row

    Code MySQL:
    SELECT *
    FROM listing a
    LEFT OUTER JOIN
    visitor b
    ON a.id = b.listing_id

    Hi, I have query like that

    The result of that is one row from listing, 15 rows from from visitor

    What should i do to output all of them together ?
    Last edited by runrunforest; Dec 31, 2008 at 22:22. Reason: question changed

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $groups = array();
    while (
    $row mysql_fetch_assoc($result)) {
        
    $groups[$row['id']][] = $row;
    }
    print_r($groups); 
    Does that help?

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not quite.

    I need something like this, say "title" is from table listing, "name" is from table visitor. I have one title and 2000 names.

    On the top of the page i want:
    Code PHP:
    $rows = mysql_fetch_assoc($result)
    {
         echo $rows[title] ;
    }

    somewhere else in the page, I want all the name appear here.

    Code PHP:
    while ( $rows = mysql_fetch_assoc($result)
    {   
         echo $rows[name];
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •