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

  • Home
  • SEARCH
  • 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 3221994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:56:25+00:00 2026-05-17T15:56:25+00:00

I have following code: SELECT q21, q21coding AS Description FROM `tresults_acme` WHERE q21 IS

  • 0

I have following code:

SELECT q21, q21coding  AS Description FROM `tresults_acme` WHERE q21 IS NOT NULL AND q21 <> '' ORDER BY q21coding

It brings back the following (excerpt):

Text                                                     Description
Lack of up to date equal pay cases&legislation - t... Content needs updating
The intranet could contain more "up to date traini... Content needs updating
Poorly set out. It is hard to find things.            Difficulty in navigating/finding content
Only use the intranet as a necessity. Will ask my ... Difficulty in navigating/finding content

Now, I’d like to display this in a table on a PHP page but am having some problems because of the way I’d like it displayed, it needs to be as follows:

Content needs updating
----------------------
[List all the comments relating to this description]

Difficulty in navigating/finding content
----------------------------------------
[List all the comments relating to this description]

and so on.

Now I think it is a For Each loop in PHP but I am having terrible difficulty getting my head around this – any ideas and suggestions very very welcome!

Thanks,

  • 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-17T15:56:25+00:00Added an answer on May 17, 2026 at 3:56 pm

    Simple approach

    1. Set prev_desc to NULL
    2. For each row print text
    3. If description is not equal to prev_desc prepend with the description for the new “section” and set prev_desc <- description

    E.g.1 (untested!),

    $prev_desc = null;
    while ($row = mysql_fetch_assoc(...)) {
        if ($prev_desc != $row['description']) {
            print '<h1>' . $row['description'] . '</h1>';
            $prev_desc = $row['description'];
        }
        print $row['text'] . '<br />'; // Formatting needed
    }
    

    Note: You must keep the ORDER BY <description-column> in order to have rows “grouped”. Otherwise this simple approach will not work.

    Less presentation-specific approach

    I could be considered more “clean” to create some kind of 2D container to “categorize” the extracted data, e.g.,

    $items = array(
        'Content needs updating' => array(
            'Lack of ...',
            'The intra...'
        ),
        ...
    );
    

    You could then loop over these items like so1:

    foreach ($items as $desc => $texts) {
        print '<h1>' . $desc . '</h1>';
        foreach ($texts as $text) {
            print $text . '<br />';
        }
    }
    

    1 As @bobince has noted, make sure that content going directly into the final HTML is properly escaped, see e.g. htmlspecialchars().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have following code: SELECT * FROM table WHERE thread = $thread AND (user
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
Let's say that I have the following code: SELECT * FROM table where company
I have the following SQL code: select val.PersonNo, val.event_time, clg.number_dialed from vicidial_agent_log val join
currently I have the following code: String select = qry.substring(select .length(),qry2.indexOf( from )); String[]
I have the following code SELECT tA.FieldName As [Field Name], COALESCE(tO_A.[desc], tO_B.[desc], tO_C.Name, tA.OldVAlue)
I have the following code select sales, price, @salesprice, {:selected => '#{@sales}'} This is
I have the following code: $('#select_albums').load(document.location.href + &action=get_albums); But this is only replacing only
I have the following code. <?php $code = $_POST['code']; // textbox $con = mysql_connect(***,****,****);
I am trying to create SQL for retrieveing a list of latests posts for

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.