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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:01:38+00:00 2026-06-15T02:01:38+00:00

I am currently doing some basic PHP and I am getting products from mysql

  • 0

I am currently doing some basic PHP and I am getting products from mysql and displaying each product with the corresponding details in a table.

Currently they are one underneath each other

Product1 Name
Product1 Price
Product1 Description

Product2 Name
Product2 Price
Product2 Description

Now I want to display them in a grid of 3 columns.
which means displaying 3 products side by side, then the 4th product is displayed underneath the 1st product and so on.

$displayAllProducts.=
        "
            <tr><td>Product Name : </td><td>$productName</td></tr>
            <tr><td>Product Price : </td><td>$productPrice</td></tr>
            <tr><td>Product Qty  : </td><td>$productQty</td></tr>
            <tr><td colspan =\"2\"><img src=\"$imagePath\" width = \"100\" height = \"100\"></td><td></td></tr>
            <tr><td colspan =\"2\"><a href=\"singleProduct.php?pid=$productID&uid=$uid\">View Product<br/><br/><br/></td><td></td></tr>   
         ";



<table>
 <?php
  echo $displayAllProducts;
 ?>
</table>
  • 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-15T02:01:39+00:00Added an answer on June 15, 2026 at 2:01 am

    Without seeing your actual code that loops through your db rows, here is a general idea. This will make each $displayAllProducts its own table, nested in the main table <td>‘s

    $i=1;  // start a general counter
    while($i<$number_of_db_rows){
    if($i%3 = 1) {   // If number is 1,4,7,etc start a new row
    $displayAllProducts.= "<tr>"; 
    }
    $displayAllProducts.=
        "
            <td>     // put each db row inside a cell
            <table>  // create a bounding table
            <tr><td>Product Name : </td><td>$productName</td></tr>
            <tr><td>Product Price : </td><td>$productPrice</td></tr>
            <tr><td>Product Qty  : </td><td>$productQty</td></tr>
            <tr><td colspan =\"2\"><img src=\"$imagePath\" width = \"100\" height = \"100\"></td><td></td></tr>
            <tr><td colspan =\"2\"><a href=\"singleProduct.php?pid=$productID&uid=$uid\">View Product<br/><br/><br/></td><td></td></tr>
            </table> 
            </td>  
         ";
    if($i%3 = 0) {   // If number is 3,6,9,etc close the row
    $displayAllProducts.= "</tr>";
    }
    $i++ // increase the counter to start again
    }  // ends the loop
    
    
    <table>
    <?php
    echo $displayAllProducts;
    ?>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently doing work experience designing the ui for some courier software in basic
I'm currently doing some testing to determine the performance implications of including an index
I'm currently doing some last-measure optimizations, mostly for fun and learning, and discovered something
I am currently doing some network programming and had a couple questions concerning timeouts.
I am currently doing some kind of reporting system.the figures, tables, graphs are all
I am doing some PloneFormGen work. Currently PloneFormGen stores entered form entries internally as
I am doing some performance critical work in C++, and we are currently using
So I have been doing some research into getting my UTF8 to print correctly.
I currently have a Linux, Apache, MySQL, PHP, Postfix web server that I setup
I have a basic MySQL table, terms , comprised of an id and term

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.