English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ive tried so many times to do this but it keeps messing up making columns all over the place.
Bascically what i want is a script in php that uses a while loop to make a table 10 rows by 10 columes. When i try it it works, it shows each table cell with its contents but it shows them all on the same line instead of making a space every 10 colums and carrying on underneath.

This is part what i made which echos them all on the same line, if you know how to do this properly ignore this code anyway:



while ($row = mysql_fetch_array($result))
{
echo "";

echo "";

}

?>


";
extract($row);
echo"$PRODUCT";
echo "

On my select mySQL query which i havnt put in i limited it to bring back 20 rows. This code echos the variable $product 20 times in a straight line. Not 10, then 10 below.
Please help, i know its possible just cant do it.

2006-10-20 02:45:46 · 2 answers · asked by peter s 1 in Computers & Internet Programming & Design

2 answers

You need to output a tag every tenth time:

echo "

";
$count = 0;
while ($row = mysql_fetch_array($result)) {
$count++;
if ($count > 10) {
echo "";
}
echo "";
if ($count > 10) {
echo "";
$count = 0;
}
}
if (($count > 0) and ($count < 10)) {
for ($i = $count + 1; $i < 10; $i++) {
echo "";
}
echo "
$PRODUCT
 ";
}
echo "
";

2006-10-20 07:55:57 · answer #1 · answered by NC 7 · 0 0

What you need to do is set up two loops...
The first loop will control how many rows you have, the second will control the number of columns in each row... this is the only way to assure that you get exactly what you are asking for.

Here is a generic example of what I mean:

while ($row <= 10)
## Set your number of rows equal to 10

{ while ($columns <= 10)
## Set your columns equal to 10
{ echo statements..... }


}
## this will add a line break after the first while loop is 1 and the second while loop cycles through 10 times

This is just a general example of how to go about doing this. It works though, I've done it several times, I'm a web designer who uses PHP aloooot!
Best Wishes :-)

2006-10-20 02:48:39 · answer #2 · answered by rachelle105210 5 · 0 0

fedest.com, questions and answers