beckjoh Posted February 24, 2008 Share Posted February 24, 2008 I need to select multiple rows (x,y data0 from two seperate tables and then store the values in two seperate array's. One will be pts the other polygon, I think I have done that. However, I then need to use all values in each array in a seperate function that is outside of the while loop for each query. The function only returns one value, instead of all of the values that should be stored in the array. Here is some of the code: <?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("database", $link); $bndresult = mysql_query("SELECT * FROM polygon ", $link); $num_rows = mysql_num_rows($bndresult); if($num_rows == 0) { echo "No rows!"; } else { // get each row while($myrow = mysql_fetch_array($bndresult, MYSQL_BOTH)) { $x = $myrow[Lon]; $y = $myrow[Lat]; $myPolygon = array("x," => $x, "y" => $y); } $result = mysql_query("SELECT * FROM point", $link); $num_rows2 = mysql_num_rows($result); if($num_rows2 == 0) { echo "No rows!"; } else { // get each row while($myrow2 = mysql_fetch_assoc($result)) { $xpoint = $myrow2[Lon]; $ypoint = $myrow2[Lat]; $point = array("x" => $xpoint, "y" => $ypoint); } foreach($point as $key => $point) { echo "$key ($point) is " . $pointLocation->pointInPolygon($point, $myPolygon) . "<br>"; } ?> This loop does not work correctly because it only loops for one of the arrays how do I loop for both?beckjoh New php-forum User Posts: 1 Joined: Sat Feb 23, 2008 9:17 am Private message Quote Link to comment Share on other sites More sharing options...
Barand Posted February 24, 2008 Share Posted February 24, 2008 Post the table structures for those two tables. And I'd remove the comma in "x," in this line $myPolygon = array("x," => $x, "y" => $y); Quote Link to comment Share on other sites More sharing options...
beckjoh Posted February 24, 2008 Author Share Posted February 24, 2008 Here is the Table structure for table `point` -- CREATE TABLE IF NOT EXISTS `point` ( `PointID` int(11) NOT NULL, `Lon` decimal(10,6) NOT NULL, `Lat` decimal(10,6) NOT NULL, `Elevation` decimal(5,1) NOT NULL, `FixType` decimal(4,0) NOT NULL, `UTCTime` decimal(7,1) NOT NULL, `Speed` decimal(3,2) NOT NULL, `Course` decimal(4,1) NOT NULL, `SF1` int(11) NOT NULL, `SF2` decimal(7,0) NOT NULL, `SF3` decimal(7,0) NOT NULL, `SF4` decimal(4,3) NOT NULL, `SF5` decimal(10,4) NOT NULL, `SF6` decimal(10,4) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; and -- Table structure for table `polygon` -- CREATE TABLE IF NOT EXISTS `polygon` ( `PolygonID` int(11) NOT NULL, `PointNum` int(11) NOT NULL, `Lon` decimal(10,6) NOT NULL, `Lat` decimal(10,6) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Quote Link to comment Share on other sites More sharing options...
Barand Posted February 24, 2008 Share Posted February 24, 2008 I thought that would help but I'm still confused. No keys. How do the table relate, if at all? Is pointNum the pointID in the points table or just a sequence number? Why are lat, long held twice, or are they the keys to join the tables? If so, aren't both your arrays identical? Quote Link to comment Share on other sites More sharing options...
beckjoh Posted February 24, 2008 Author Share Posted February 24, 2008 The two tables are not related. One table is a set of points, the other hold the xy vertices of a polygon. I am trying to select all points that fall within a polygon. I may be attempting something that is not logical. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 24, 2008 Share Posted February 24, 2008 See http://www.phpfreaks.com/forums/index.php/topic,108445.msg436434.html#msg436434 Quote Link to comment Share on other sites More sharing options...
beckjoh Posted February 24, 2008 Author Share Posted February 24, 2008 That solution looks great, but I still have the same problem because the author of that script physically added the point and polygon values. I need the script to pull all of the values from a mysql table. The only way I know how to fill the array is through two seperate loops, but to run the function, I would need to be able for each array to loop through all the points. Therefore my first question remains, can you first fill two arrays and then loop them together. Or do you use the explode function to fix the problem? Quote Link to comment Share on other sites More sharing options...
beckjoh Posted February 26, 2008 Author Share Posted February 26, 2008 Barand, Any more thoughts on my problem? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 26, 2008 Share Posted February 26, 2008 If you want to create an array to create a polygon then while($myrow = mysql_fetch_array($bndresult, MYSQL_BOTH)) { $x = $myrow['Lon']; $y = $myrow['Lat']; $myPolygon[] = $x ; $myPolygon[] = $y; } Quote Link to comment Share on other sites More sharing options...
beckjoh Posted February 26, 2008 Author Share Posted February 26, 2008 Thanks, I think I have it working. I was going to try your function on http://www.phpfreaks.com/forums/index.php/topic,108445.msg436434.html#msg436434 to see if it works. Do I need the imagecreate function or is it within php? Thanks again. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 26, 2008 Share Posted February 26, 2008 It's in the gd extension 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.