Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:37:47+00:00 2026-06-08T11:37:47+00:00

I have a PHP array that produces four columns per row of a table.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:37:48+00:00Added an answer on June 8, 2026 at 11:37 am

    You should really check out the syntax for the PHP if statement .

    $counter = 0;
    while ($counter < count($set)) : 
        $item = $set[$counter];
        if($counter % 2 == 0): ?>
            <tr class="q<?php echo $counter; ?>">                   
        <?php endif;?>
                <td><a class="question" href="javascript:soundManager.play('<?php echo $item['qurl'] ?>','audio/part2/type1/type1_<?php echo $item['qurl'] ?>.mp3');"><?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 endif;?>
        <?php $counter++; ?>
    <?php endwhile; ?>
    <?php if(($counter +1) % 2 == 0): ?>
        </tr>
    <?php endif; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP array that produces four columns per row of a table.
I have a php array that has a bunch of data that I need
I have a PHP file that returns a JSON array. I need to extract
I have a php page that produces an array of elements. For the sake
I have a PHP array that looks like this: Array{ [0] { 'id' =>
In PHP I have an array that looks like this: $array[0]['width'] = '100'; $array[0]['height']
I have php code that puts some values into an Array as follows: $hunter=addslashes($MessageArray[1]);
I have an multi-dimensional array that I want to send to a PHP script
I have an array in php that contains all the lines of a text
I have a PHP file that contains a large array (about 90KB). I'm considering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.