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

  • SEARCH
  • Home
  • 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 6130403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:51:16+00:00 2026-05-23T16:51:16+00:00

Explination Through PHP I am generating an 8×8 grid of div’s. The problem is

  • 0

Explination

Through PHP I am generating an 8×8 grid of div’s. The problem is not getting this to happen (Although my methods may need to change), but rather the x and y coordinates of the blocks (stored as the id).

The Code

class Grid
{
    function __construct()
    {
        $i = 0;
        $w = 'white';
        $b = 'black';
        for($y=1; $y<=8; $y++)
        {
            for($x=1; $x<=8; $x++)
            {
                if($i % 2)
                    echo "<div class='$w' id='{$x}{$y}'></div>";
                else
                    echo "<div class='$b' id='{$x}{$y}'></div>";    
                $i++;

            }
            echo "<br clear='all' /> \n";
            $i++; //offset color for next row   
        }            
    }
}

Problem

While this class does it’s job of displaying the grid, the problem is the coordinates are not how I need them. The coordinates output in the following fashion because of how the HTML is rendered (imagine each bracket as the div’s position on the screen):

note: [x coord, y coord]

[1,1] [2,1] [3,1] 
[1,2] [2,2] [3,2] 
[1,3] [2,3] [3,3]

I actually need the ‘reverse’ of this, so that it starts at the bottom left, and the coordinates resemble that of a typical grid, ie:

[1,3] [2,3] [3,3] 
[1,2] [2,2] [3,2] 
[1,1] [2,1] [3,1]

I am sure there many ways to pull this off, so the answer will go to the most elegant solution, not the fastest. Thanks!

  • 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-05-23T16:51:17+00:00Added an answer on May 23, 2026 at 4:51 pm

    I think this is as simple as changing to:

     for($y=8; $y>=1; $y--)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem setting a cookie through PHP on IE. It works
I just thought I would comb through this to find the answer: http://svn.php.net/viewvc/php/php-src/ But
I'm new to NUnit and looking for an explination as to why this test
I've not used strtok before, the PHP manual doesn't give a very good explanation.
I am not very familiar with .htaccess and have already searched through the net
Not really sure if this is possible, but I am running this on Terminal:
I have been working through Microsoft's ASP.NET MVC tutorials, ending up at this page
I can´t find an explanation to this behaviour (SQL Server 2008 + PHP 5.2.14)
I'm looking for a library which do this : Retrieve a JSON through an
I've had something strange happen lately with php script I use to send emails

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.