Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6239803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:27:16+00:00 2026-05-24T11:27:16+00:00

Say I have a table containing articles (article_id, article_name) and another table containing the

  • 0

Say I have a table containing articles (article_id, article_name) and another table containing the names of people (person_id, person_name) that ordered the articles. Plus an intermediary table, say articles-people (article_id, person_id).

Is there an elegant way I could do a single SELECT to get all the articles and the associated purchasers such that the articles would each listed in headers and the people are listed under the respective articles they’ve bought?

Also, is there a SELECT that would fetch the needed information but avoid a result like this (which looks like a badly structured DB):

  • article_id:1,article_name:penlight,purchaser_id:1, purchaser_name:fred
  • article_id:1,article_name:penlight,purchaser_id:2, purchaser_name:albert
  • article_id:1,article_name:penlight,purchaser_id:3, purchaser_name:sonia
  • …
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:27:17+00:00Added an answer on May 24, 2026 at 11:27 am

    This should print out rows with values.

       $res = mssql_query('SELECT *
            FROM articles a
            join articles-people ap on a.article_id=ap.articleid
            join people p on ap.person_id=p.personid');
    
        $results = array();
        $finalResuls = array();
        while($row = mssql_fetch_assoc($res))
        {
           $results[] = $row;
        }
    
        foreach($results as $result)
        {
           /* This makes an array with key:value pairs as string. */
           foreach($result as $k => $v)
           {
              $finalResults[] = $k . ': ' . $v;
           }
           $string = '';
           /* Will concatenate data for each result row into a single string */
           foreach($result as $k => $v)
           {
              $string .= $k . ': ' . $v;
           }
           $finalResults[] = $string;
        }
    

    So that you can have both solutions in the same post, here is the solution you were talking about with JNK.

    $res = mssql_query('SELECT * from article');
    
    $results = array();
    while($row = mssql_fetch_assoc($res))
    {
       $id = $row['article_id'];
       $res2 = mssql_query("SELECT * from people p join articles-people ap on p.person_id=ap.person_id where ap.article_id='$id'");
       while($row2 = mssql_fetch_assoc($res2))
       {
          foreach($row2 as $k => $v)
          {
             $results[$id][] = $k . ': ' . $v;
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a table containing articles and you want want to display
Lets say I have a table containing several hundred million rows that looks something
Lets say that I have a table containing users . Each row in that
Say I have at database table containing information about a news article in each
Let's say I have a table containing following data: | id | t0 |
Say I have a table called xml that stores XML files in a single
For examples sake, lets say I have a table containing these columns ID (primary
Say I have a post table containing the fields post_id and parent_post_id . I
I have a table say, ITEM, in MySQL that stores data as follows: ID
Let's say we have a [Valuations] table containing several values per date and per

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.