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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:26:32+00:00 2026-06-03T06:26:32+00:00

I am trying to dynamically display a list of products in two columns (side

  • 0

I am trying to dynamically display a list of products in two columns (side by side) and I am not sure how to do it with tables

Here is my code that displays all products in one column

    $productCount = sqlsrv_num_rows($stmt); // count the output amount
$columncount = 0;
$dynamicList = '<table width="744" border="0" cellpadding="6"><tr>';
while($row = sqlsrv_fetch_array($stmt)){ 
         $id = $row["productID"];
         $product_name = $row["product_name"];
         $product_price = $row["product_price"];
         $dynamicList .= '<td width="135"><a href="product_details.php?productID=' . $id . '"><img src="images/products/Small/Men/' . $id . '.jpg" alt="' . $product_name . '" width="129" height="169" border="0"></a></td>
<td width="593" valign="top">' . $product_name . '<br>
  £' . $product_price . '<br>
  <a href="product_details.php?productID=' . $id . '">View Product Details</a></td>';

  if($columncount == 2){
    $dynamicList .= '</tr><tr>';
    $columncount = 0;
  }else
    $columncount++; 
 }

$dynamicList .= '</tr></table>';

<?php echo $dynamicList; ?><br>

How do I get my products to display in two columns instead of one?

Updated my post with the working solution

  • 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-03T06:26:33+00:00Added an answer on June 3, 2026 at 6:26 am

    You are creating a table for each row in the resultset

    It should be something like this:

    $columncount = 0;
    $dynamicList = '<table width="744" border="0" cellpadding="6"><tr>';
    while($row = sqlsrv_fetch_array($stmt)){ 
             $id = $row["productID"];
             $product_name = $row["product_name"];
             $product_price = $row["product_price"];
             $dynamicList .= '<td width="135"><a href="product_details.php?productID=' . $id . '"><img src="images/products/Men/' . $id . '.jpg" alt="' . $product_name . '" width="129" height="169" border="0"></a></td>
    <td width="593" valign="top">' . $product_name . '<br>
      £' . $product_price . '<br>
      <a href="product_details.php?productID=' . $id . '">View Product Details</a></td>';
    
      if($columncount == 3){
        $dynamicList .= '</tr><tr>';
        $columncount = 0;
      }else
        $columncount++; 
     }
    
    $dynamicList .= '</tr></table>';
    
    echo $dynamicList;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create a page for a university project that dynamically displays a
Him I'm trying to add a jQuery tooltip to a dynamically generated list, the
I'm trying to display a list of Notes. I have an ItemsControl which is
I'm trying to create a view that contains a list of checkboxes that is
I have a large nested list that I am trying to animate using jquery
I am trying to dynamically build a list of admin actions using the get_actions()
I want to populate a List dynamically and display the list when i hover
I have a list of tasks (name, starts_at) and I'm trying to display them
I'm trying to create a web page that will display an appropriate user control
I am trying to create a simplified code to insert images dynamically into a

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.