# evenly distribute items up to 14 items

if \$x<=4 do one row
if \$x<=8 && \$x>=5 two rows
if \$x>=9 && \$x<=14 three rows

I need to do

<table>
<tr>
<td>

and I want the items to evenly distributed
with the number of items per row being important

if \$x==5
3 items on first row
2 items on second row

if \$x==7
4 items on first row
3 items on second row

if \$x==9
3 items on first row
3 items on second row
3 items on third row

if \$x== 14
5
5
4
is what I want

LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I think this is what you are saying, please see if it works like you want:
``````<?php

\$html = "<table>";

/*
and I want the items to evenly distributed
with the number of items per row being important
*/

if (\$x==5) {

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 2; \$i++) {
2 items on second row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

if (\$x==7) {

\$html .= "<tr>";
for (\$i = 0; \$i < 4; \$i++) {
//4 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
3 items on second row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

if (\$x==9) {

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

if (\$x==14) {

\$html .= "<tr>";
for (\$i = 0; \$i < 5; \$i++) {
//5 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 5; \$i++) {
//5 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 4; \$i++) {
//4 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

\$html .= "</table>";

// output
echo \$html;

?>
``````
0
Author Commented:
i want this done for all the values
1 to 14
0
Commented:
Here, use this one (don't forget to assign a value to "x"):
``````<?php

\$html = "<table>";

\$x = 5;

if (\$x==5) {

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 2; \$i++) {
//2 items on second row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

if (\$x==7) {

\$html .= "<tr>";
for (\$i = 0; \$i < 4; \$i++) {
//4 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on second row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

if (\$x==9) {

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 3; \$i++) {
//3 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

if (\$x==14) {

\$html .= "<tr>";
for (\$i = 0; \$i < 5; \$i++) {
//5 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 5; \$i++) {
//5 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

\$html .= "<tr>";
for (\$i = 0; \$i < 4; \$i++) {
//4 items on first row
\$html .= "<td>Item \$i</td>";
}
\$html .= "</tr>";

}

\$html .= "</table>";

// output
echo \$html;

?>
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Sorry, I don't understand what you're asking.  Do you mean if x is 1-14?  Please try to explain in detail.
0
Author Commented:
my question did not ask 1-14 items
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.