PHP Grid

C++, C#, Java, PHP, ect...
Post Reply
User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

PHP Grid

Post by VZdemon »

Could someone help me with this code for makeing a grid in php. thanks.

Code: Select all

<?php
	$rows = 3;
	$cols = 4;
	
	$black = false;
	$white = false;
	
	$width = 20;
	$height = 20;
	
	$text[5][5] = array(
					"tile","tile","tile","tile",
					"tile","tile","tile","tile",
					"tile","tile","tile","tile",
					"tile","tile","tile","tile"
					);
	echo $array[0][1];
	
	for($c=0;$c<$cols;$c++){
		$x=$c*40;
		if($black==false){
		echo "<spam style='
					left:$x;
					width:40;
					height:20;
					background-color:WHITE;
					border:1px solid GRAY; 
				'>Tile</spam>";
		$black = true;
		}else{
		echo "<spam style='
					left:$x;
					width:40;
					height:20;
					background-color:BLACK;
					color:WHITE;
					border:1px solid GRAY; 
				'>Tile</spam>";
		$black = false;	
		}
		for($t=0;$t<$rows;$t++){
			$y=$t*20;
			if($white==false){
			echo "<br/><spam style='
						top:$y;
						width:40;
						height:20;
						background-color:BlACK;
						color:WHITE;
						border:1px solid GRAY; 
					'>Tile</spam>";
			$white=true;
			}else{
			echo "<br/><spam style='
						top:$y;
						width:40;
						height:20;
						background-color:WHITE;
						color:BLACK;
						border:1px solid GRAY; 
					'>Tile</spam>";
			$white=false;
			}
		}
	}
	
	?>
it's VZdaemon on xbox live
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: PHP Grid

Post by Xaleph »

What is that code? It`s a mess currently. Try doing in small steps. You want something with colors, but it`s not working correct?

Anyway, you have an X axis and an Y axis. So rows == y and cols == x.

So in order for the grid to display, you have to go trough all Y, in each Y ( as long as Y <= $rows ) go trough each X as X <= $cols.

So :

Code: Select all

for($y = 0; $y <= $cols; $y ++ ){
      for($x = 0; $x <= $rows ; $x ++ )
      { 
           // print a block
      }
} 
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: PHP Grid

Post by Xaleph »

Code: Select all

<?php
error_reporting(E_ALL);
ini_set("display_errors", true);

       $rows = 3;
       $cols = 4;

       $black = false;
       $white = false;

       $width = 20;
       $height = 20;


       $text[5][5] = array(
                   "tile","tile","tile","tile",
                   "tile","tile","tile","tile",
                   "tile","tile","tile","tile",
                   "tile","tile","tile","tile"
                   );

       echo "<div style='width:300px; height: 500px;'>
             ";
       for($yt = 0; $yt <= $cols ; $yt++ )
       {
             echo '<div style="height: 60px; margin: 10px; background-color: red; width: 100%;">
                   ';
            for($xt = 0 ; $xt <= $rows ; $xt++ )
            {
                  echo '
                        <div style="float: left; font-size: 11px; color: white; width: 50px; height: 40px; margin: 10px; background: green;">
                              Y = '.$yt.' <br/> X = '.$xt.'
                        </div>
                  ';
            }
            echo "
                  </div>";
       }

       echo "
             </div>";

?>

User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

Re: PHP Grid

Post by VZdemon »

thanks. :)
it's VZdaemon on xbox live
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP Grid

Post by Jackolantern »

And just for the record, it is span, not spam ;)
The indelible lord of tl;dr
Post Reply

Return to “Coding”