# Solution 1 :

Your logic is fine, just the limit to the for loop seems to be miscalculated.

Right now, for the variable `group = (qty/limit)/limit`, you have an extra division by limit here.

Whatever your need maybe for that division, you can simply use the value of `tabs` in your for loop condition, or assign it to another temporary variable its up to you.

``````for(\$i = 0; \$i < \$tabs; \$i++) {
echo "Group {\$alphabet[\$i]}".'<br>';
}
``````

Cheers!

# Solution 2 :

Maybe this could helps you

``````<?php

//\$tabs = (\$qty / \$limit);
//\$group = \$tabs / \$limit;

\$alphabet   = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
\$return     = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
\$a          = array_chunk(\$return, 3);
//\$a            = array_chunk(\$return, \$limit);

\$key        = 0;
\$group      = array();
\$r          = count(\$a);

foreach(\$alphabet as \$v)
{
if(\$key < \$r)
{
if(!isset(\$group[\$v]))
{
\$group[\$v] = array();
}

\$group[\$v] = \$a[\$key];

\$key++;
}
}
``````
``````print_r(\$group);
``````

# Problem :

I need to generate a dynamic text in accordance with the number of data that comes from the database.

In a html List, I need to display the following text as example:

• GROUP A
• GROUP B
• GROUP C

If the amount of records coming from the DB is only 1000, then only one item list is displayed. 1000 records equals 1 Item list.

The text must be dynamically changed as described above.
Each text in the list is displayed for 1000 records.

The code below statically displays 11 items

I’ve made a few tries on the code below but still to no avail.

This code is working, but it display only the static text.

``````\$return .= "<div id='test_id'><ul>";
// \$qty = 10424 / \$limit = 1000
// \$tabs = \$qty / \$limit = 10,424
\$tabs = \$qty/\$limit;

for (\$i=0; \$i < \$tabs ; \$i++)
{
\$start = \$i * \$limit + 1;
\$end = (\$i + 1) * \$limit;
\$color = 'classpA';
\$message = '<small>GROUP A</small>';
if (\$i < \$tab_selected) {
\$color = 'classB';
\$message = 'RESERVED';
}
\$active = \$i == \$tab_selected ? "active" : "";

\$return .= "<li class='tab {\$color} {\$active}' tab-id='#tab-".\$i."'>

<span class='available {\$color}_text'><small>{\$message}</small></span>

<a href='#' class='{\$color}_text'>".\$start." - ".min(\$end,\$qty)."</a></li>";

}
\$return .= "</ul></div>";
``````

And this is that logic that i`m trying to apply

``````\$qty = 18424;
\$limit = 1000;
\$tabs = (\$qty / \$limit);

\$group = \$tabs / \$limit;

\$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

for(\$i = 0; \$i < \$group; \$i++) {
echo "Group {\$alphabet[\$i]}".'<br>';
}

echo 'Qtd Group= '.\$group.' Value Var Tabs= '.\$tabs;

``````

`https://www.tehplayground.com/zyVzmaeYnTyyA4S9`

How can I make the magic happen?

### Comment posted by Ken Lee

At least you need to make a query on the db to get the \$qty value. (but there is no such thing in your codes)

### Comment posted by Paulo do Porto

@KenLee, yes, I did not post the whole code. There is no query on the DB here, but as i commented, this peace of code works “static”.