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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:46:05+00:00 2026-06-06T12:46:05+00:00

I am trying to format some html output from my db using php and

  • 0

I am trying to format some html output from my db using php and here’s my problem:

How it should be formated:

...
<li>
    <div class="row-wrapper">
       <div class="some-class-1">ARRAY-ELEMENT-1</div>
       <div class="some-class-1">ARRAY-ELEMENT-2</div>
       <div class="some-class-1">ARRAY-ELEMENT-3</div>
       <div class="some-class-2">ARRAY-ELEMENT-4</div>
    </div>
    <div class="row-wrapper">
      <div class="some-class-1">ARRAY-ELEMENT-5</div>
      <div class="some-class-1">ARRAY-ELEMENT-6</div>
      <div class="some-class-1">ARRAY-ELEMENT-7</div>
      <div class="some-class-2">ARRAY-ELEMENT-8</div>
    </div>
    <div class="row-wrapper">
      <div class="some-class-1">ARRAY-ELEMENT-9</div>
      <div class="some-class-1">ARRAY-ELEMENT-10</div>
      <div class="some-class-1">ARRAY-ELEMENT-11</div>
      <div class="some-class-2">ARRAY-ELEMENT-12</div>
    </div>
</li>
<li>
  <div class="row-wrapper">
    <div class="some-class-1">ARRAY-ELEMENT-13</div>
    <div class="some-class-1">ARRAY-ELEMENT-14</div>
    <div class="some-class-1">ARRAY-ELEMENT-15</div>
    <div class="some-class-2">ARRAY-ELEMENT-16</div>
  </div>
  <div class="row-wrapper">
    <div class="some-class-1">ARRAY-ELEMENT-17</div>
    <div class="some-class-1">ARRAY-ELEMENT-18</div>
    <div class="some-class-1">ARRAY-ELEMENT-19</div>
    <div class="some-class-2">ARRAY-ELEMENT-20</div>
  </div>
  <div class="row-wrapper">
    <div class="some-class-1">ARRAY-ELEMENT-21</div>
    <div class="some-class-1">ARRAY-ELEMENT-22</div>
    <div class="some-class-1">ARRAY-ELEMENT-23</div>
    <div class="some-class-2">ARRAY-ELEMENT-24</div>
  </div>
</li>
... etc.

Data is held inside an array gathered from mysql db, so far I got to this:

$num_thumbs = 4; //Number od elemets in a row
$result = myQueryFunction("SELECT * FROM table_name ORDER BY Id ASC"); 
$num_rows = mysql_num_rows($result); 
if (!empty($num_rows)) {
  while ($row = mysql_fetch_array($result)) {
    $thumbs_array[] = "<a href=\"" . $row[0] . "\"><img src=\"" . $row[1] . "\"";
  }
  $thumb_p = "<div>\n";
  mysql_free_result($result);
  $i = 1;
  foreach ($thumbs_array as &$thumb_link) {
    if ($i == $num_thumbs) {
        $i = 1;
        $thumb_p .= "<div class=\"some-class-2\">" . $thumb_link . "</div>";
        $thumb_p .= "</div>\n<div class=\"row-wrapper\">\n";
    } else {
            $thumb_p .= "\t\n<div class=\"some-class-1\">" . $thumb_link . "</div>";
        $i++;
    }

  }
  $thumb_p .= "\n</div>\n";
}

print($thumb_p);

this covers only this part of code formatting:

  <div class="row-wrapper">
    <div class="some-class-1">ARRAY-ELEMENT-13</div>
    <div class="some-class-1">ARRAY-ELEMENT-14</div>
    <div class="some-class-1">ARRAY-ELEMENT-15</div>
    <div class="some-class-2">ARRAY-ELEMENT-16</div>
  </div>
  <div class="row-wrapper">
    <div class="some-class-1">ARRAY-ELEMENT-17</div>
    <div class="some-class-1">ARRAY-ELEMENT-18</div>
    <div class="some-class-1">ARRAY-ELEMENT-19</div>
    <div class="some-class-2">ARRAY-ELEMENT-20</div>
  </div>
  <div class="row-wrapper">
    <div class="some-class-1">ARRAY-ELEMENT-21</div>
    <div class="some-class-1">ARRAY-ELEMENT-22</div>
    <div class="some-class-1">ARRAY-ELEMENT-23</div>
    <div class="some-class-2">ARRAY-ELEMENT-24</div>
  </div>

I’ve been thinking of using some variable $newList = null; that will be updated at each row, so I can check if it has changed the next one.
any ideas? Thanks in advance 🙂

  • 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-06-06T12:46:06+00:00Added an answer on June 6, 2026 at 12:46 pm

    It seems you’re trying to put an li every three div. In this case, you can do this :

    $thumb_p = "<li>\n<div class=\"row-wrapper\">\n";
    mysql_free_result($result);
    $i = 1;
    $j = 0;
    foreach ($thumbs_array as &$thumb_link) {
      if ($i == $num_thumbs) {
          $i = 1;
          $thumb_p .= "<div class=\"some-class-2\">" . $thumb_link . "</div>";
          $thumb_p .= "</div>\n";
          if($j == 3)
          {
              $thumb_p .= "</li>\n<li>";
              $j = 0;
          }
          $thumb_p .= "<div class=\"row-wrapper\">\n";
          $j++;
      } else {
          $thumb_p .= "\t\n<div class=\"some-class-1\">" . $thumb_link . "</div>";
          $i++;
      }
    }
    $thumb_p .= "\n</div>\n</li>\n";
    

    I can’t actually try it but I think it’s okay. A li is added every three row-wrapper you print.

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

Sidebar

Related Questions

Using jQuery v1.6.4, I'm trying dynamically format some objects. Here is my code: <html>
I am trying to format some bad html to output into a pop window.
I am trying to format some c# output so that a number always has
I'm trying to sanitize/format some input using regex for a mixed latin/ideographic(chinese/japanse/korean) full text
I'm trying to do some image processing on iPhone. I'm using http://developer.apple.com/library/ios/#qa/qa2010/qa1702.html to capture
I am trying to format some groovy code in vim Firstly I the command
I am trying to get some errors returned in JSON format. So, I made
I'm trying to format a table from XML. Lets say I have this line
I'm getting an 'System.OutOfMemoryException' when trying to generate some HTML reports. How can I
I'm trying to format my list of items, where the html goes like this:

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.