Page 1 of 1

While Loop - how to break in groups of 10

Posted: Wed Jul 12, 2006 9:05 am
by michlcamp
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have table full of addresses and want to break them into groups of 10 addresses each...
don't know how to write the loop...

all I've got so far is:

Code: Select all

$query="SELECT 'address' FROM customers";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
echo "$address <br>";

$i++;
}
What I'd like to end up with is 10 addresses in a list then a space (line break), 10 more and a space...

All help appreciated...
thanks.mc


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jul 12, 2006 9:19 am
by JayBird

Code: Select all

$query="SELECT 'address' FROM customers";

$result=mysql_query($query);

$num=mysql_numrows($result);

$i=0;

while ($i < $num) 
{
    echo "$address <br>";
    if($i % 10 == 0)
        echo "<br><br>";
    $i++;
}

Posted: Wed Jul 12, 2006 10:15 am
by michlcamp
couldn't that to work as written..
thanks.mc

Posted: Wed Jul 12, 2006 10:27 am
by JayBird
michlcamp wrote:couldn't that to work as written..
thanks.mc
Huh? :?

Posted: Wed Jul 12, 2006 10:30 am
by michlcamp
couldn't get that to work.
produced a blank page.

Posted: Wed Jul 12, 2006 10:39 am
by Grim...
No, it wouldn't - but your original code wouldn't do anything either.

Code: Select all

$query="SELECT 'address' FROM customers";

$result=mysql_query($query);

$num=mysql_numrows($result);

$i=0;

while ($a_row = mysql_fetch_object( $result ) )
{
    echo "$a_row->address<br>";
    if($i % 10 == 0)
        echo "<br><br>";
    $i++;
}
Assuming 'address' is the name of one of the fields in your 'customers' table.