473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

simple loop? help

I do probably need a good coffee, but I can't find out a simple way to do
so.

Let's say I want to create a table using a number I receive.
For every number, I must have a table with maximum 5 columns.

Example:
10 will gives 2 rows of 5 columns
12 will gives 2 rows of 5 columns and a row of 2 columns.
.....

The problem is that I've to keep the value of every cell like this for 12
1 2 3 4 5
6 7 8 9 10
11 12

How to do so ?
I've done this so far:
$columns = 10;
$lines = $columns / 5;

for($K=0;$K<=($lines+1);$K++)
<?php for($K=0;$K<=($lines+1);$K++){?>
<tr>
<?php
for($I=1;$I<=($columns-($K*5));$I++)
echo('<td align="center">Colonne '.($K*5+$I).'</td>');
?>
</tr>

But It doesn't work properly. I can't figure out a simple way.

Thanks for helping.

Bob
Dec 13 '05 #1
3 1515
Bob Bedford wrote:
I do probably need a good coffee, but I can't find out a simple way to do
so.

Let's say I want to create a table using a number I receive.
For every number, I must have a table with maximum 5 columns.

Example:
10 will gives 2 rows of 5 columns
12 will gives 2 rows of 5 columns and a row of 2 columns.
....

The problem is that I've to keep the value of every cell like this for 12
1 2 3 4 5
6 7 8 9 10
11 12

How to do so ?

<snip>
Try this (not tested, you may have to adjust it)

<?php
$received = 12;

echo '<table>';
$count = 1;
while ($count <= $received) {
if (($count % 5) == 1) echo '<tr>';
echo "<td>$count</td>";
if (($count % 5) == 0) echo '</tr>';
++$count;
}
if (($count % 5) != 1) { // generate empty cells
while ($count++ % 5) echo '<td>&nbsp;</td>';
echo '</tr>';
}
echo '</table>';

Dec 13 '05 #2
Bob Bedford wrote:
I do probably need a good coffee, but I can't find out a simple way to
do so.

Let's say I want to create a table using a number I receive.
For every number, I must have a table with maximum 5 columns.

Example:
10 will gives 2 rows of 5 columns
12 will gives 2 rows of 5 columns and a row of 2 columns.
....

The problem is that I've to keep the value of every cell like this for 12
1 2 3 4 5
6 7 8 9 10
11 12

How to do so ?
I've done this so far:
$columns = 10;
$lines = $columns / 5;

for($K=0;$K<=($lines+1);$K++)
<?php for($K=0;$K<=($lines+1);$K++){?>
<tr>
<?php
for($I=1;$I<=($columns-($K*5));$I++)
echo('<td align="center">Colonne '.($K*5+$I).'</td>');
?>
</tr>

But It doesn't work properly. I can't figure out a simple way.

Thanks for helping.

Bob

I wouldn't use tables for this, I would use divs.
example:http://www.reenie.org/test/test21.php
<?
include "../../lib/geolib.php";
$s="
.cell{width:16%; margin:1px;float:left;border:solid 1px; padding:2px;}
h4{margin:0; padding:1em 0 0 0; clear:both;}
";

$t="5 cell css table";

$num=8;
$p.=h4("number of cells is $num");
for($i=0; $i<$num; $i++)
$p.=div("Colonne $num",NULL,'cell');

$num=12;
$p.=h4("number of cells is $num");
for($i=0; $i<$num; $i++)
$p.=div("Colonne $num",NULL,'cell');

echo html($p, head($t,NULL,$s));
?>
Dec 13 '05 #3
meltedown wrote:

I wouldn't use tables for this, I would use divs.
example:http://www.reenie.org/test/test21.php

Here's a non liquid version of the same page:
http://www.reenie.org/test/test22.php

I simply added a wrapper with a width
Dec 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
22
by: lokman | last post by:
Hi, In the following code, can someone tell me the difference between *p++ and p++ ? I can see both achieve the same result. Thanks a lot !
13
by: na1paj | last post by:
here's a simple linked list program. the DeleteNode function is producing an infinit loop i think, but i can't figure out where.. #include <stdio.h> typedef struct { char *str; //str is a...
0
by: Vaughn | last post by:
I'm working on a simple screensaver (it just displays a different image every 5 seconds) but I'm having trouble displaying an image in my form using the BackGroundImage property. I was trying to...
26
by: jacob navia | last post by:
Summary: I have changed (as proposed by Chuck) the code to use isalpha() instead of (c>='a' && c <= 'z') etc. I agree that EBCDIC exists :-) I eliminated the goto statement, obviously it is...
6
by: porky008 | last post by:
I need to modify the following program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the...
23
by: AndersWang | last post by:
Hi, dose anybody here explain to me why memset would be faster than a simple loop. I doubt about it! In an int array scenario: int array; for(int i=0;i<10;i++) //ten loops
0
by: rich | last post by:
Hi all, I have a fairly complex "feed" application that recieves messages from an external user-supplied API via a callback function, and attempts to forward these messages to another...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.