I have a PHP array that produces four columns per row of a table. I need to modify my php so I have eight columns per row instead of four.
For example. The current output looks like:
COL 1 COL 2 COL 3 COL 4
COL 5 COL 6 COL 7 COL 8
COL 9 COL 10 COL 11 COL 12
COL 13 COL 14 COL 15 COL 16
But I need it to look like this:
COL 1 COL 2 COL 3 COL 4 COL 5 COL 6 COL 7 COL 8
COL 9 COL 10 COL 11 COL 12 COL 13 COL 14 COL 15 COL 16
On a previous question I asked if I could do this via CSS/HTML. It was strongly suggested that I modify my PHP code instead. I received the pseudo code to do this, but I’m having trouble getting it to work. The logic is as follows:
if($counter % 2 == 0)
output startting <tr> tag
output the four <td> tags with data
if(($counter +1) % 2 == 0)
output closing <tr> tag
Here is my current code:
<form>
<table>
<?php $counter = 0;
while ($counter < 20) :
$item = $set[$counter]
if($counter % 2 == 0) ?>
<tr class="q<?php echo $counter; ?>">
<td><a class="question" href="<?php echo $item['qurl'] ?>');"><?php echo $item['q'] ?></a></td>
<td><input class="a1" type="text" name="a1" maxlength="3" size="3" /></td>
<td><input class="a2" type="text" name="a2" maxlength="3" size="3" /></td>
<td><input class="submit submit-<?php echo $counter; ?>" type="submit" value="Submit" /></td>
<?php if(($counter +1) % 2 == 0) ?>
</tr>
<?php $counter++; ?>
<?php endwhile; ?>
</table>
</form>
I’m a beginner so please excuse my novice attempt. Thanks in advance.
You should really check out the syntax for the PHP if statement .