Pavlos1316
Pavlos1316

Reputation: 444

DynamicList with Multiple Columns

This is my dynamicList (one of you helped me to create multiple columns in it.) But I forgot that by creating multiple columns/rows inseide a table, if I have 20 items to be displayed, I have to wait until the whole table is ready, and I don't want that.

How can I fix it so it displays each row inside a new table?

if ($productCount > 0) {
        $i=0;
        $dynamicListBody = '<table width: 90%; margin-right: auto; margin-left: auto; color: #00E6AA;>';
        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" height="80px" width="40px" alt="' . $product_name . '" />
                     </td>
                     <td width="35%">
                    <span class=itmttl>' . $product_name . '</span>
                    <br />
                    <span class=text>' . $details . '
                    <br />
                    €' . $price . '</span>
                    <br />
                      <form name="bd_itm" id="bd_itm" method="post" action="help_scripts/cart_functions.php">
                    <input type="hidden" name="pid" id="pid" value="' . $id . '" />
                    <input type="submit" name="button" id="button' . $id . '" value="Add to Cart" />
                    <br />
                    <br />
                      </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();

Upvotes: 1

Views: 99

Answers (1)

Kalle H. V&#228;ravas
Kalle H. V&#228;ravas

Reputation: 3615

No, you don't have to wait until the hole table is ready, but actually wait until PHP is done loading it. Meaning, that PHP runs the hole script before it displays it.

I think that displaying each row as separate table is extremely BAD idea. Rather, optimize your PHP so it would run faster or add flush() before the while loop end (at the end of each row..)

Upvotes: 1

Related Questions