onlyican Posted August 28, 2006 Share Posted August 28, 2006 HeyLet me try and explainI have a map, and I am using the GD LIB functions to complete the mapOn the Map it self, there is 100 boxes.I have the Top Left corner location of each box in an arrayThis location will be the Grid location(longitude / Latitude)Now I have a MySQL table, which will contain what is in each box. (There status)Then with this status, I will add an image depending on the status that is in the table(Then that Location in the box will have another image in it, using GD LIB)How I am working this out is like the following[code]<?php//This is the possible locations, as it is a square the X and Y will have the same locations$locations_array = array("10","70","130","190","250","310","370","430","490","500");//This is so If I add another location, i dont have to change all of the code$num_locations = count($locations_array);//setting a var to check everything is working$num_results = 0;//Run a for loop to get each location from the array for the X axisfor($a = 0; $a < $num_locations; $a ++){//Now to get the Y axis, for each X axisfor($b = 0; $b <$num_locations; $b ++){//Create the X and Y location into one $location = $locations_array[$a].".".$locations_array[$b]//Now just a Visual Test for meecho $location."<br />\n";//And for the testing to make sure they are all coming out$num_results = $num_results + 1;}}?>[/code]This SHOULD show 100 results in a listand $num_results will be 100That may help explain how I am getting all of the locations (saves having an array of 100)Now, I want to use $location to check what the status is for its locationIf I run a query in the middle of the for loops, then that means 100 queries in that page alone, which will kill my serverCan anyone think of a better way to retrieve the status of all locations, for me to compare them to $location Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 [code]$query = "SELECT status FROM locations WHERE location IN (" . implode(",", $locations_array) . ")";[/code]Then you would loop through to put them into an array using the location as the key (assuming all locations occur only once). Then to get the status, just use [code]$location_status_array[$location][/code] to get the status Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 28, 2006 Author Share Posted August 28, 2006 I was just thinking of doing thatCheers hombre Quote Link to comment Share on other sites More sharing options...
Barand Posted August 28, 2006 Share Posted August 28, 2006 1 query.[code]table----------longlatstatus<?php$sql = "SELECT long, lat, status FROM mytable";$res = mysql_query ($sql) or die (mysql_error());while (list($long, $lat, $status) = mysql_fetch_row($res)) { $status_array[$long][$lat] = $status;}//Run a for loop to get each location from the array for the X axisfor($a = 0; $a < $num_locations; $a ++){ //Now to get the Y axis, for each X axis for($b = 0; $b <$num_locations; $b ++){ $status = $status_array[$a][$b]; // draw map square using status value } }?>[/code] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 PHP is weakly typed, so it will convert the keys to whatever format you request them in. So long as the two are equivalent, either string, int, or float, then they will equate to eachother. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 28, 2006 Author Share Posted August 28, 2006 its ok, I found an error, I done if(is_string($var){and it was coming up as string, so I knew it wasn't that when I was testing I run a queryThen I ran the query again cos I forgot I run the first queryso they were overwritting each other, causing the mess up.Thanks anywayIts looking nicea 610px by 610px image, with 100 boxes, being filled with color from the table. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.