Jump to content

How the theory would work to display a set list of products using columns


Recommended Posts

This is really just a general question that I am quite interested in developing.

 

Say I had a list of products with the following attributes right?

 

productid = 1 (smallint(3))

productname = "Product 1" (varchar, to reduce space)

price = 25.99 (double, more precise for currency?) --please correct me if I am wrong

 

But say this spanned out to say 6 products per line on the user viewing the page.

 

With then 5 rows down.

 

product1 | product2 | product3 | product4 | product5 | product6

 

product7 | product8 | product9 | product10 | product11 | product12

 

And so on until all products have been displayed right?

 

How would I do this theoretically in PHP to limit that no of results per row?

 

Always been confused on how this is doable, want to eventually construct my own ecommerce, really get into the nuts and bolts of it.

 

Thanks and I appreciate any reples,

Jeremy.

 

Are you displaying the results in a table? If you are then you could just use a counter in your loop that retrieves the data.

 

$maxrows = 3; // max number of rows per column
$count = 0; // counter for loop

echo ' '; // start table
echo ' ';  // start first column in table

loop { // whatever kind of loop you decide to use

if($count == $maxrows){ // if the $counter variable equals max rows per column var the
    $count = 0; // set $count back to 0
    echo ' '; // close your column, start a new one
}

$count++; // increment $count by 1

echo ' '; //new row

} // close loop

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.