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 7088253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:46:38+00:00 2026-05-28T07:46:38+00:00

$myfile = mysql_query($query_myfile, $db) or die(mysql_error()); $totalRows_myfile = mysql_num_rows($myfile); $typ_d = ”; $test=”; while

  • 0
$myfile = mysql_query($query_myfile, $db) or die(mysql_error());
$totalRows_myfile = mysql_num_rows($myfile);
$typ_d = '';
$test='';


while ( $row_myfile = mysql_fetch_assoc($myfile) ) 
{
   if ( $typ_d != $row_myfile[ 'typ_d' ] ) 
   {

       $typ_d = $row_myfile[ 'typ_d' ];

       echo "<h2>$typ_d</h2>";

   }
   if ( $test != $row_myfile[ 'test' ] ) 
   {

       $test = $row_myfile[ 'test' ];

       echo "<h3>$test</h3>";
   }

   echo "<li><a href=\"myfileDetail.php?myfile_id=".$row_myfile['myfile_id']. "\">";
   echo $row_myfile['shortname'].' ';
   echo $row_myfile['name']; ?></a></li>

   <?php } ?>

This code list out element in group and subgroups like this

Typ_d (group) generated by

echo "<h2>$typ_d</h2>";

test(subgroup) generated by

echo "<h3>$test</h3>";

then the lists generated by

echo "<li><a href=\"myfileDetail.php?myfile_id=".$row_myfile['myfile_id']. "\">";
       echo $row_myfile['shortname'].' ';
       echo $row_myfile['name']; ?></a></li>

I have a problem generation the html tag as follow

<h2>Typ_d1</h2>
<h3> Test1</h3>
<ul>
  <li> List1</li>
  <li> List2 </li>
  <li>List3 </li>
</ul>
<h2>Typ_d2 </h2>
<h3>Test2</h3>
<ul>
  <li> List1</li>
  <li> List2</li>
  <li> List3</li>
</ul>
<h2> Typ_d3</h2>
<h3> Test3</h3>
<ul>
  <li> List1</li>
  <li> List2 </li>
  <li>List3 </li>
</ul>

I have tried so much but i cannot get it with the right order ..need help please

the current out put has not <ul> tag and I would like to put it in side the code

this is the current output

<li> List1</li>
  <li> List2 </li>
  <li>List3 </li>

<h2>Typ_d2 </h2>
<h3>Test2</h3>

  <li> List1</li>
  <li> List2</li>
  <li> List3</li>

<h2> Typ_d3</h2>
<h3> Test3</h3>

  <li> List1</li>
  <li> List2 </li>
  <li>List3 </li>
  • 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-28T07:46:39+00:00Added an answer on May 28, 2026 at 7:46 am

    Ok, without doing a major restructuring of your code (e.g. into an MVC pattern), you’re better off compiling the data into an array first and then looping over that to generate the output, like @Blowski said. Something like this:

    $myfile = mysql_query($query_myfile, $db) or die(mysql_error());
    
    
    $groups = array();
    
    while ( $row_myfile = mysql_fetch_assoc( $myfile ) ) {
    
      $typ_d = $row_myfile[ 'typ_d' ];
    
      $groups[ $typ_d ][ 'h2' ] = $row_myfile[ 'typ_d' ];
    
      $groups[ $typ_d ][ 'h3' ] = $row_myfile[ 'test' ];
    
      $groups[ $typ_d ][ 'files' ][] = <<<DOCHERE
    <li>
    <a href="myfileDetail.php?myfile_id="{$row_myfile[ 'myfile_id' ]}">{$row_myfile[ 'shortname' ]} {$row_myfile[ 'name' ]}</a>
    </li>
    DOCHERE;
    
    }
    // while
    
    
    foreach ( $groups as &$group ) {
    
      $group[ 'files' ] = join( "\n\n", $group[ 'files' ] );
    
      $group = <<<DOCHERE
    <h2>
    {$group[ 'h2' ]}
    </h2>
    
    <h3>
    {$group[ 'h3' ]}
    </h3>
    
    <ul>
    
    {$group[ 'files' ]}
    
    </ul>
    DOCHERE;
    
    }
    // foreach
    
    
    echo join( "\n\n\n", $groups );
    

    Notes:

    • You should almost certainly be html-escaping the variable values before outputting them in HTML.

    • I’ve eliminated the ugly concatenation for HTML output generation and replaced it with variable interpolation.

    • I’ve eliminated the ill-advised double-quoting of HTML output strings and used HEREDOCs instead.

    • There are a lot of variations on details of how you could do this, e.g. call array_key_exists() in the while loop instead of just re-assigning the h2 and h3 keys each time, assign $groups[ $typ_d ] by reference to shorten the other assignment statements, etc.

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

Sidebar

Related Questions

I have created a file named MyFile.db using SQLite3 from my C#.net application. This
I mistakenly added files to Git using the command: git add myfile.txt I have
If I use an URL like http://mysite/myfolder/myfile.dll , I get a dialog Do you
I've added a file to the 'index' with: git add myfile.java How do I
I'm wanting to get the filepath ie /sites/default/files/myfile.pdf for my file uploads. I'm using
I have a file as documentRoot/app/webroot/myFile.php I need to be able to access this
I have a file, myfile.py , which imports Class1 from file.py and file.py contains
Let's say there is a file called myfile.txt with the following contents: one two
Given a path such as "mydir/myfile.txt" , how do I find the file's absolute
I have a problem in integrating PHP and JQuery: My main file is MyFile.html

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.