admin gives the number of products printed per row php mysql

hello guys,
i develop an eshop from scratch, i want when a user choose the category he wants then the products per row he can see its not a static number, for example 3 items per row

i want admin to give for example this : 2;3;4; so thats means : the first row has 2 items, the second 3 items and the third 4 items

how can i manage this?

thats the code i developed :

$productsPerRow = 3;
$productsPerPage = 100;
$sql = “SELECT* from tbl_product order by pd_id desc”;
$result = dbQuery(getPagingQuery($sql, $productsPerPage));
$pagingLink = getPagingLink($sql, $productsPerPage, “c=$catId”);
$numProduct = dbNumRows($result);
if ($numProduct > 0 ) {
$i = 0;
while ($row = dbFetchAssoc($result)) {
extract($row);
if ($pd_thumbnail) {
$pd_thumbnail = WEB_ROOT . ‘images/product/’ . $pd_thumbnail;
} else {
$pd_thumbnail = WEB_ROOT . ‘images/no-image-small.png’;
}
if ($i % $productsPerRow == 0) {
echo ‘

’;
}
?> <?php echo $prodname;?> if ($i % $productsPerRow == $productsPerRow - 1) { echo ''; } $i += 1; }

First, please place your code inside the PHP tabs by pressing the PHP button and insert the code between
the tags. Makes it much easier for us to copy it to our editors. Thanks!

Well, to do this in a program, you will have to create a database table to hold the ADMIN’s selections.
Since you indicate that the admin can alter those numbers, you have to have a table to hold them in.
The table should just be simple, like the row number and the number the ADMIN entered for that row.

Then, in your display code, it would just retrieve the list of rows and numbers into a simple array. Then,
when displayed, the code would check the array to know how many items to display. It should be a quite
simple task to add that into your code. Within your WHILE clause, you would need to increment your $i
number and compare it to your $itemsperrow($rownumber) to see if it is at the limit. You would have to
keep track of row numbers. I used $rownumber as an example for this and $itemsperrow as a sample
name for your array of ADMIN entered numbers.

Something like that should work for you… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service