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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:17:41+00:00 2026-05-22T14:17:41+00:00

First of all I am not very familiar with this. $dynamicListBody = ; $sql

  • 0

First of all I am not very familiar with this.

 $dynamicListBody = "";
$sql = mysql_query("SELECT * FROM products WHERE category='Body' ORDER BY id ASC");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($sql)){
             $id = $row["id"];
         $product_name = $row["product_name"];
         $details = $row["details"];
         $price = $row["price"];
         $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
         $dynamicListBody .= '
         <table width="95%">
              <tr>
               <td width="10%">
        <img style="border:#666 1px solid;" src="../stock_photos/' . $id . '.png" alt="' . $product_name . '" />
           </td>
               <td width="35%">
            <span class=itmttl>' . $product_name . '</span>
        <br />
                <span class=text>' . $details . '
                <br />
                €' . $price . '</span>
        <br />
                <form id="bd_itm1" name="bd_itm1" method="post" action="help_scripts/cart_functions.php">
                <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
                <input type="submit" name="button" id="button" value="Add to Cart" />
                </form>
           </td>
           <td width="5%">
           </td>
           <td width="10%">
           </td>
           <td width="35%">
        <br />
        <form id="bd_itm2" name="bd_itm2" method="post" action="help_scripts/cart_functions.php">
                <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
                <input type="submit" name="button" id="button" value="Add to Cart" />
                </form>
           </td>
              </tr>
             </table>';
    }
} else {
    $dynamicListBody = "We have no products listed in our store yet";
}
mysql_close();
?>

This displays my results in the first column only. How can I display results in the second column as well
like
1 – a | 2 – b
3 – c | …
without changing the above table layout?

  • 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-22T14:17:41+00:00Added an answer on May 22, 2026 at 2:17 pm
    x2    
    <?php 
         $sql = mysql_query("SELECT * FROM products WHERE category='Body' ORDER BY id ASC");
         $productCount = mysql_num_rows($sql); // count the output amount
         if ($productCount > 0) {
            $i=0;
            $dynamicListBody = '<table width="95%">';
            while($row = mysql_fetch_array($sql)){
                $id = $row["id"];
                $product_name = $row["product_name"];
                $details = $row["details"];
                $price = $row["price"];
                $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
                $dynamicListBody .= ($i==0) ? '<tr>':''; 
                $dynamicListBody .= '
                    <td width="10%">
                          <img style="border:#666 1px solid;" src="../stock_photos/' . $id . '.png" alt="' . $product_name . '" />
                    </td>
    
                    <td width="35%">
                      <span class=itmttl>' . $product_name . '</span>
                      <br />
                      <span class=text>' . $details . '<br />&euro;' . $price . '</span>
                       <br />
                        <form id="bd_itm1" name="bd_itm1" method="post" action="help_scripts/cart_functions.php">
                        <input type="hidden" name="pid" id="pid" value="'.$id.'" />
                        <input type="submit" name="button" id="button" value="Add to Cart" />
                        </form>
                    </td>';
                $dynamicListBody .= ($i==1) ? '</tr>':''; 
                $i++;
                ($i==2) ? $i=0:'';
            } 
            $dynamicListBody.='</table>';
         } else {
            $dynamicListBody = "We have no products listed in our store yet";
         }
         mysql_close();
        ?>
    //4
    
        <?php 
         $sql = mysql_query("SELECT * FROM products WHERE category='Body' ORDER BY id ASC");
         $productCount = mysql_num_rows($sql); // count the output amount
         if ($productCount > 0) {
            //iteration set to 0
            $i=0;
            $dynamicListBody = '<table width="95%">';
            while($row = mysql_fetch_array($sql)){
                $id = $row["id"];
                $product_name = $row["product_name"];
                $details = $row["details"];
                $price = $row["price"];
                $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
                //$i controls the first <tr> in the loop
                $dynamicListBody .= ($i==0) ? '<tr>':''; 
                $dynamicListBody .= '
                    <td width="10%">
                          <img style="border:#666 1px solid;" src="../stock_photos/' . $id . '.png" alt="' . $product_name . '" />
                    </td>
    
                    <td width="35%">
                      <span class=itmttl>' . $product_name . '</span>
                      <br />
                      <span class=text>' . $details . '<br />&euro;' . $price . '</span>
                       <br />
                        <form id="bd_itm1" name="bd_itm1" method="post" action="help_scripts/cart_functions.php">
                        <input type="hidden" name="pid" id="pid" value="'.$id.'" />
                        <input type="submit" name="button" id="button" value="Add to Cart" />
                        </form>
                    </td>';
                //is 3 as first iteration is 0 meaning 4 rows will get outputted when $i is 3 as started on 0 not 1
                $dynamicListBody .= ($i==3) ? '</tr>':''; 
                $i++;
                //note $i was set to 4(above $i++) before checking, meaning 4 rows have been outputted
                ($i==4) ? $i=0:'';
            } 
            $dynamicListBody.='</table>';
         } else {
            $dynamicListBody = "We have no products listed in our store yet";
         }
         mysql_close();
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of I'm very sorry but this questions is not so so specific. All
Hallo, first of all, i am not very familiar when it comes to xml
First of all, I'm an Objective-C novice. So I'm not very familiar with OS
first i must admit that i'm not very familiar with sql server's recursive CTE's
First of all I want to point out that I'm not very familiar with
first of all: this is not the same as this . The ModelBackend has
First of all I'm not sure this is even possible, however I need to
First of all I am not a designer. so this question is may be
First of all: This question is not directly programming related. However, the problem only
First of all, im finding the iPhone online docs to be not-so-very thoroughly clear

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.