...

View Full Version : Mapping script help!



Mentally
08-27-2009, 10:01 PM
Hey there!

I wanted to make a mapping script where you have 4x4 regions with 124x124 squares in every region, with their own unique coordinates.

Here's a reference image of what I mean.
http://reapers.netii.net/map.jpg

That's where my problems start, I've not really got much of a clue on to where or how to start doing this.

I wanted it to be dynamical because, when members and users input their coordinates, it'd get saved in mysql and when you access the different map regions they would get loaded and put in their correct place on the map. Empty spaces being blank.

Any help at all would be massively appreciated.

Cheers,
- Mentally.

Phil Jackson
08-27-2009, 10:07 PM
this is quite a big project for this HELP forum my friend. Even I must turn you down.

Phil Jackson
08-27-2009, 10:19 PM
ARGH i ant help it...
right you will have to create 16 scripts to generate 124 X 124 cell tables (before anyone says anything i know). After you have created them you will have to use CSS to align them correctly. After more thought you will find you can now your script down to just one script and send it through a loop.... i might start you on your way... if your nice.

Mentally
08-27-2009, 10:21 PM
Hehe, well, I actually thought it would be a lot easier than it sounds.

But the real problem I think really is just how to make the 124x124 grid when you click on a region.

Phil Jackson
08-27-2009, 10:39 PM
just an idea

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ACT Web Designs - Home</title>
<style type="text/css">
table.table {
float:left;
}
div.clear {
clear:both;
}
#wrapper {
width:1500px;
}
</style>
</head>
<body>
<div id="wrapper">
<?php

$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");

for($y = 0; $y <= 15; $y++)
{
echo "<table class=\"table\" name=\"start_".($y*124)." style=\"paddong:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 124; $x++)
{
echo "<tr style=\"paddong:0; margin:0; background-color:".$colors16[$y]."\">";
for($z = 1; $z <= 124; $z++)
{
echo "<td name=\"".$y."-".($x*$z)."\" width=\"1px\" height=\"1px\" style=\"paddong:0; margin:0\" cellpadding=\"0\"></td>\n";
}
echo "</tr>";
}
echo "</table>\n";
}

?>
<div class="clear"></div>
</div>
</body>
</html>

Phil Jackson
08-27-2009, 10:45 PM
be warned its time consuming. thousands of lines of outputted code.

Phil Jackson
08-27-2009, 10:52 PM
think my calcs are wrong...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ACT Web Designs - Home</title>
<style type="text/css">
table.table {
float:left;
}
div.clear {
clear:both;
}
#wrapper {
width:900px;
}
</style>
</head>
<body>
<div id="wrapper">
<?php

$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");

for($y = 0; $y <= 15; $y++)
{
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; background-color:".$colors16[$y]."\">";
for($z = 1; $z <= 62; $z++)
{
echo "<td name=\"".$y."-".($x*$z)."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0\" cellpadding=\"0\"></td>\n";
}
echo "</tr>";
}
echo "</table>\n";
}

?>
<div class="clear"></div>
</div>
</body>
</html>

Mentally
08-27-2009, 10:53 PM
That's really awesome, Phil. It's exactly what I'm looking for and a really huge leap in the right direction for me.

Now all I'm looking at is to get some kind of visual representation for all the 16 "fields" and grabbing any coordinate points added from the database and display them accordingly when viewing a region for example. (Could possibly just leave the rest of the fields blank inheriting the background color with a border around or something.)

But so far you've been really awesome. Thanks a lot for your help. :)

I'll try and see if I can develop this little script further now.

Phil Jackson
08-27-2009, 11:06 PM
not to be a stuck in the mud but see if this helps:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ACT Web Designs - Home</title>
<style type="text/css">
table.table {
float:left;
}
div.clear {
clear:both;
}
#wrapper {
width:900px;
}
</style>
</head>
<body>
<div id="wrapper">
<?php

$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");

for($y = 0; $y <= 15; $y++)
{
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; \">";
for($z = 1; $z <= 62; $z++)
{
if(isset($_POST['x']))
{
$coOrd = $_POST['y']."-".$_POST['x']."-".$_POST['z'];
$tdName = ($y+1)."-".$x."-".$z;
if($coOrd==$tdName)
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color: black\" cellpadding=\"0\"></td>\n";
die("");
}
else
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$colors16[$y]."\" cellpadding=\"0\"></td>\n";
}
}
else
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$colors16[$y]."\" cellpadding=\"0\"></td>\n";
}
}
echo "</tr>";
}
echo "</table>\n";
}

?>
<div class="clear"></div>
</div>
<form action="1.php" method="post">
<p>y - (box 1 - 16) <input type="text" name="y" /></p>
<p>X - <input type="text" name="x" /></p>
<p>Z - <input type="text" name="z" /></p>
<input type="submit" name="submit" />
</form>
</body>
</html>

Phil Jackson
08-27-2009, 11:08 PM
quite an interesting project. You'll notice that the script will stop at that exact co-ord

Phil Jackson
08-27-2009, 11:18 PM
This will give a cross ref effect:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ACT Web Designs - Home</title>
<style type="text/css">
table.table {
float:left;
}
div.clear {
clear:both;
}
#wrapper {
width:900px;
}
</style>
</head>
<body>
<div id="wrapper">
<?php

$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");

for($y = 0; $y <= 15; $y++)
{
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; \">";
for($z = 1; $z <= 62; $z++)
{
if(isset($_POST['x']))
{
$coOrd = $_POST['y']."-".$_POST['x']."-".$_POST['z'];
$tdName = ($y+1)."-".$x."-".$z;
if($coOrd==$tdName)
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"2px\" height=\"2px\" style=\"padding:0; margin:0; background-color:black\" cellpadding=\"0\"></td>\n";

}
else
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$colors16[$y]."\" cellpadding=\"0\"></td>\n";
}
}
else
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$colors16[$y]."\" cellpadding=\"0\"></td>\n";
}
}
echo "</tr>";
}
echo "</table>\n";
}

?>
<div class="clear"></div>
</div>
<form action="1.php" method="post">
<p>y - (box 1 - 16) <input type="text" name="y" /></p>
<p>X - <input type="text" name="x" /></p>
<p>Z - <input type="text" name="z" /></p>
<input type="submit" name="submit" />
</form>
</body>
</html>

Phil Jackson
08-27-2009, 11:33 PM
getting better:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ACT Web Designs - Home</title>
<style type="text/css">
* {
padding:0;
margin:0;
}
div.clear {
clear:both;
}
#wrapper {
width:900px;
margin:30px;
}
div.wrapper2 {
width:200px;
height:200px;
border:1px solid #000;
float:left;
position:relative;
}
div.boxNum {
position:absolute;
top:-10px;
left:-10px;
}
table.table {
margin:5px;
}
</style>
</head>
<body>
<div id="wrapper">
<?php

$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");

for($y = 0; $y <= 15; $y++)
{
echo "<div class=\"wrapper2\">\n";
echo "<div class=\"boxNum\">".($y+1)."</div>\n";
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; \">";
for($z = 1; $z <= 62; $z++)
{
if(isset($_POST['x']))
{
$coOrd = $_POST['y']."-".$_POST['x']."-".$_POST['z'];
$tdName = ($y+1)."-".$x."-".$z;
if($coOrd==$tdName)
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"2px\" height=\"2px\" style=\"padding:0; margin:0; background-color:black\" cellpadding=\"0\"></td>\n";

}
else
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$colors16[$y]."\" cellpadding=\"0\"></td>\n";
}
}
else
{
echo "<td name=\"".$y."-".$x."-".$z."\" width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$colors16[$y]."\" cellpadding=\"0\"></td>\n";
}
}
echo "</tr>";
}
echo "</table>\n";
echo "</div>\n";
}

?>
<div class="clear"></div>
</div>
<form action="1.php" method="post">
<p>y - (box 1 - 16) <input type="text" name="y" /></p>
<p>X - <input type="text" name="x" /></p>
<p>Z - <input type="text" name="z" /></p>
<input type="submit" name="submit" />
</form>
</body>
</html>

Mentally
08-27-2009, 11:54 PM
Getting really good now, Phil!

Now all that's missing is breaking all of the 16 regions into links for example, and by using an ID or something be able to determine the max Y/X coordinates.

For example taking Region 1:
X coordinates: 0,0 - 124,0
Y coordinates: 0,0 - 0,124

Though I don't understand how to get those cross-lined from 0,0 to 124,124 or if it's possible.

Loading field and coordinate information from a database and administering it on the visual map. Could possibly have a huge grid with the records showing up in a color within the square, maybe increasing the size from 1x1 pixels to 2x2 or something to see better.

Phil Jackson
08-27-2009, 11:59 PM
i will talk more in the morning (time for bed the missus says) but i was thinking more along the lines of hovering over a co-ord and displaying the infor at the side or something you need to keep the grtad as small as you can for loading times. I will work more on it in the mornig. If you could send me a mysql_dump for the structure of the table used for this is would be much easyer. Cya soon

Mentally
08-28-2009, 12:59 AM
Goodnight, Phil! Looking forward to work more with you tomorrow!

Here's the MySQL dump as you requested by the way!


-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 28, 2009 at 01:56
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `evonymap`
--

-- --------------------------------------------------------

--
-- Table structure for table `map_locations`
--

CREATE TABLE IF NOT EXISTS `map_locations` (
`player_name` varchar(25) NULL,
`flat_level` smallint(2) NULL,
`flat_name` varchar(25) NOT NULL,
`x_coordinate` smallint(3) NOT NULL,
`y_coordinate` smallint(3) NOT NULL,
`id` smallint(5) NOT NULL,
`updated` smallint(10) NOT NULL,
UNIQUE KEY `Map ID` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Ndogg
08-28-2009, 04:52 AM
I need this too...

Ndogg
08-28-2009, 05:25 AM
What I really need is a part that checks the database if that square is occupied and if it is, the color changes.

Phil Jackson
08-28-2009, 08:53 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ACT Web Designs - Home</title>
<style type="text/css">
* {
padding:0;
margin:0;
}
div.clear {
clear:both;
}
#wrapper {
width:900px;
margin:30px;
}
div.wrapper2 {
width:200px;
height:200px;
border:1px solid #000;
float:left;
position:relative;
}
div.boxNum {
position:absolute;
top:-10px;
left:-10px;
}
table.table {
margin:5px;
}
</style>
</head>
<body>
<div id="wrapper">
<?php
//BELOW CHECKS TO SEE IF COORDS CAN BE ASIGNED ALL COULD BE WRAPPED UP IN SEPERETE FILE AND THE INCLUDED
$con = mysql_connect("79.1####2", "we###ts", "AC###0##3");
$db = mysql_select_db("we##-acc##ounts", $con);

if(isset($_POST['submit']))
{
$z_coordinate = $_POST['z'];
$x_coordinate = $_POST['x'];
$y_coordinate = $_POST['y'];
$query = mysql_query("SELECT * FROM `map_locations` WHERE z_coordinate = '$z_coordinate' AND x_coordinate = '$x_coordinate' AND y_coordinate = '$y_coordinate'");
if(mysql_num_rows($query)!=0)
{
while($array = mysql_fetch_array($query))
{
$z_cord = $array["z_coordinate"];
$x_cord = $array["x_coordinate"];
$y_cord = $array["y_coordinate"];

$coord = $y_cord.$x_cord.$z_cord;
$coOrd = $_POST['y'].$_POST['x'].$_POST['z'];
if(trim($coord)==trim($coOrd))
{
echo "<p>The space has been taken.</p>";
break;
}
else
{
mysql_query("INSERT INTO `map_locations` (z_coordinate, x_coordinate, y_coordinate) VALUES ('$z_coordinate', '$x_coordinate', '$y_coordinate')")or die(mysql_error());
echo "<p>Update complete.</p>";
}
}
}
else
{
$z_coordinate = $_POST['z'];
$x_coordinate = $_POST['x'];
$y_coordinate = $_POST['y'];
mysql_query("INSERT INTO `map_locations` (z_coordinate, x_coordinate, y_coordinate) VALUES ('$z_coordinate', '$x_coordinate', '$y_coordinate')")or die(mysql_error());
echo "<p>Update complete.</p>";
}
}
//END

//FUNCTION BELOW IS WHAT TESTS TO SEE WHAT COORD IS IN USE (THIS COULD ALL BE WRAPPED ONTO A SEPERATE FILE AND INCLUDED AT THE TOP

$query2 = mysql_query("SELECT * FROM `map_locations` order by auto_id");
$x_cords = array();
$y_cords = array();
$z_cords = array();
if(mysql_num_rows($query2)!=0)
{
while($array2 = mysql_fetch_array($query2))
{
$z_cords[] = $array2["z_coordinate"];
$x_cords[] = $array2["x_coordinate"];
$y_cords[] = $array2["y_coordinate"];
}
}

function findExist($x, $y, $z, $color, $x_cords, $y_cords, $z_cords)
{
$returnTrue=0;
foreach($y_cords as $key => $y_cord)
{
if(trim($y_cord)==trim($y))
{
$coord = $y.$x.$z;
$co0rd = $y_cords[$key].$x_cords[$key].$z_cords[$key];
if(trim($coord)==trim($co0rd))
{
$returnTrue++;
}
}
}
if($returnTrue!=0)
{
return "width=\"2px\" height=\"2px\" style=\"padding:0; margin:0; background-color:black\" cellpadding=\"0\"";
}
else
{
return "width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$color."\" cellpadding=\"0\"";
}
}
//END COORD FUNCTION

//THIS WOULD BE THE MAIN OUTPUTTING SCRIPT
$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");
for($y = 0; $y <= 15; $y++)
{
echo "<div class=\"wrapper2\">\n";
echo "<div class=\"boxNum\">".($y+1)."</div>\n";
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; \">";
for($z = 1; $z <= 62; $z++)
{
if(isset($_POST['x']))
{
$coOrd = $_POST['y']."-".$_POST['x']."-".$_POST['z'];
$tdName = ($y+1)."-".$x."-".$z;
if($coOrd==$tdName)
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" width=\"2px\" height=\"2px\" style=\"padding:0; margin:0; background-color:black\" cellpadding=\"0\"></td>\n";
}
else
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" ".findExist($x,($y+1), $z, $colors16[$y], $x_cords, $y_cords, $z_cords)."></td>\n";
}
}
else
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" ".findExist($x, ($y+1), $z, $colors16[$y], $x_cords, $y_cords, $z_cords)."></td>\n";
}
}
echo "</tr>";
}
echo "</table>\n";
echo "</div>\n";
}
//END SCRIPT
?>


<div class="clear"></div>
</div>
<form action="1.php" method="post">
<p>y - (box 1 - 16) <input type="text" name="y" /></p>
<p>X - <input type="text" name="x" /></p>
<p>Z - <input type="text" name="z" /></p>
<input type="submit" name="submit" />
</form>
</body>
</html>

mUST CHANGE TABLE TO:


CREATE TABLE IF NOT EXISTS `map_locations` (
`auto_id` int(10) NOT NULL auto_increment,
`player_name` varchar(25) default NULL,
`flat_level` smallint(2) default NULL,
`flat_name` varchar(25) NOT NULL,
`z_coordinate` smallint(3) NOT NULL,
`x_coordinate` smallint(3) NOT NULL,
`y_coordinate` smallint(3) NOT NULL,
`id` smallint(5) NOT NULL,
`updated` smallint(10) NOT NULL,
PRIMARY KEY (`auto_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;

Mentally
08-28-2009, 02:13 PM
Really, a job well done there Phil!

I've tried out the script and it seems to save the coordinates I put in the database but I can't see any difference on the map when i test it out.

Phil Jackson
08-28-2009, 02:39 PM
<style type="text/css">
* {
padding:0;
margin:0;
}
div.clear {
clear:both;
}
#wrapper {
width:900px;
margin:30px;
}
div.wrapper2 {
width:200px;
height:200px;
border:1px solid #000;
float:left;
position:relative;
}
div.boxNum {
position:absolute;
top:-10px;
left:-10px;
}
table.table {
margin:5px;
}
</style>
is this inserted and not conflicting with any other selectors?

Phil Jackson
08-28-2009, 03:02 PM
http://www.actwebdesigns.co.uk/demo1/grid.gif

Mentally
08-28-2009, 03:58 PM
It's not conflicting from what I can see on my part. For some reason it's jut not showing up anything when I load the page. Hmm.

Edit:
I've been taking some time off of IRL stuff to look through some of you code. Most focus has been on the output of the data. I understand very well how the XY-axis works but I'm wondering how you're calculating or making out the equivilent of what the XY-axis does.

Like this.
http://reapers.netii.net/grid.jpg

Since coordinates go from upper left corner, and so on. As shown in the first image. (Yeah it's a ****load of number combinations, 124x124 squares with xxx,yyy combinations - Going from the cordinates given in the X axis, then down towards the coordinate on the Y axis. For example: 483, 441)

Would it be easy to name every cell thats echoed out with the XY-axis combination they're representing, or is that actually done in here? If so I'd guess it would be
name=\"".($y+1)."-".$x."-".$z."\" that does it.

I consider myself somewhat good at PHP but when it comes to loops I'm just nulled. Heh.

Phil Jackson
08-29-2009, 07:03 AM
man, i have hell of a hangover i'll talk and explain when my heads straight.

Phil Jackson
08-29-2009, 12:43 PM
I did try to split it up for you. The following code is for when the submit button is pressed. It just checks whether the space is taken or not:



//BELOW CHECKS TO SEE IF COORDS CAN BE ASIGNED ALL COULD BE WRAPPED UP IN SEPERETE FILE AND THE INCLUDED
$con = mysql_connect("79.1####2", "we###ts", "AC###0##3");
$db = mysql_select_db("we##-acc##ounts", $con);

if(isset($_POST['submit']))
{
$z_coordinate = $_POST['z'];
$x_coordinate = $_POST['x'];
$y_coordinate = $_POST['y'];
$query = mysql_query("SELECT * FROM `map_locations` WHERE z_coordinate = '$z_coordinate' AND x_coordinate = '$x_coordinate' AND y_coordinate = '$y_coordinate'");
if(mysql_num_rows($query)!=0)
{
while($array = mysql_fetch_array($query))
{
$z_cord = $array["z_coordinate"];
$x_cord = $array["x_coordinate"];
$y_cord = $array["y_coordinate"];

$coord = $y_cord.$x_cord.$z_cord;
$coOrd = $_POST['y'].$_POST['x'].$_POST['z'];
if(trim($coord)==trim($coOrd))
{
echo "<p>The space has been taken.</p>";
break;
}
else
{
mysql_query("INSERT INTO `map_locations` (z_coordinate, x_coordinate, y_coordinate) VALUES ('$z_coordinate', '$x_coordinate', '$y_coordinate')")or die(mysql_error());
echo "<p>Update complete.</p>";
}
}
}
else
{
$z_coordinate = $_POST['z'];
$x_coordinate = $_POST['x'];
$y_coordinate = $_POST['y'];
mysql_query("INSERT INTO `map_locations` (z_coordinate, x_coordinate, y_coordinate) VALUES ('$z_coordinate', '$x_coordinate', '$y_coordinate')")or die(mysql_error());
echo "<p>Update complete.</p>";
}
}
//END


The following code (split into two parts) is what makes the dots on the screen:
part1 - puts all coords in the database into arrays.

$query2 = mysql_query("SELECT * FROM `map_locations` order by auto_id");
$x_cords = array();
$y_cords = array();
$z_cords = array();
if(mysql_num_rows($query2)!=0)
{
while($array2 = mysql_fetch_array($query2))
{
$z_cords[] = $array2["z_coordinate"];
$x_cords[] = $array2["x_coordinate"];
$y_cords[] = $array2["y_coordinate"];
}
}
Part2
The code below takes the data from the arrays and then cross-ref's them with what current row and cell that is being processed in the code UNDER the code below (lol).


function findExist($x, $y, $z, $color, $x_cords, $y_cords, $z_cords)
{
$returnTrue=0;
foreach($y_cords as $key => $y_cord)
{
if(trim($y_cord)==trim($y))
{
$coord = $y.$x.$z;
$co0rd = $y_cords[$key].$x_cords[$key].$z_cords[$key];
if(trim($coord)==trim($co0rd))
{
$returnTrue++;
}
}
}
if($returnTrue!=0)
{
return "width=\"2px\" height=\"2px\" style=\"padding:0; margin:0; background-color:black\" cellpadding=\"0\"";
}
else
{
return "width=\"1px\" height=\"1px\" style=\"padding:0; margin:0; background-color:".$color."\" cellpadding=\"0\"";
}
}


And finally this peice of code brings il all together and prints out the tables


$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");
for($y = 0; $y <= 15; $y++)
{
echo "<div class=\"wrapper2\">\n";
echo "<div class=\"boxNum\">".($y+1)."</div>\n";
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; \">";
for($z = 1; $z <= 62; $z++)
{
if(isset($_POST['x']))
{
$coOrd = $_POST['y']."-".$_POST['x']."-".$_POST['z'];
$tdName = ($y+1)."-".$x."-".$z;
if($coOrd==$tdName)
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" width=\"2px\" height=\"2px\" style=\"padding:0; margin:0; background-color:black\" cellpadding=\"0\"></td>\n";
}
else
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" ".findExist($x,($y+1), $z, $colors16[$y], $x_cords, $y_cords, $z_cords)."></td>\n";
}
}
else
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" ".findExist($x, ($y+1), $z, $colors16[$y], $x_cords, $y_cords, $z_cords)."></td>\n";
}
}
echo "</tr>";
}
echo "</table>\n";
echo "</div>\n";
}


EDIT:
This code is wrong. Change to:

$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");
for($y = 0; $y <= 15; $y++)
{
echo "<div class=\"wrapper2\">\n";
echo "<div class=\"boxNum\">".($y+1)."</div>\n";
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; \">";
for($z = 1; $z <= 62; $z++)
{

$coOrd = $_POST['y']."-".$_POST['x']."-".$_POST['z'];
$tdName = ($y+1)."-".$x."-".$z;
if($coOrd==$tdName)
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" width=\"2px\" height=\"2px\" style=\"padding:0; margin:0; background-color:black\" cellpadding=\"0\"></td>\n";
}
else
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" ".findExist($x,($y+1), $z, $colors16[$y], $x_cords, $y_cords, $z_cords)."></td>\n";
}
}
echo "</tr>";
}
echo "</table>\n";
echo "</div>\n";
}

WAIT... just give me 2mins to write it correctly

Phil Jackson
08-29-2009, 12:53 PM
//THIS WOULD BE THE MAIN OUTPUTTING SCRIPT
$colors16 = array("red", "blue", "green", "orange", "brown", "black", "white", "pink", "purple", "yellow", "green", "red", "orange", "brown", "pink", "purple", "yellow");
for($y = 0; $y <= 15; $y++)
{
echo "<div class=\"wrapper2\">\n";
echo "<div class=\"boxNum\">".($y+1)."</div>\n";
echo "<table class=\"table\" name=\"start_".($y*62)." style=\"padding:0; margin:0\" cellpadding=\"0\">\n";
for($x = 1; $x <= 62; $x++)
{
echo "<tr cellpadding=\"0\" style=\"padding:0; margin:0; \">";
for($z = 1; $z <= 62; $z++)
{
echo "<td name=\"".($y+1)."-".$x."-".$z."\" ".findExist($x,($y+1), $z, $colors16[$y], $x_cords, $y_cords, $z_cords)."></td>\n";
}
echo "</tr>";
}
echo "</table>\n";
echo "</div>\n";
}
//END SCRIPT


That is correct.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum