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 Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/ 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); Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-475034 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; Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-475041 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? Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-475283 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. Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-475294 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 Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-475302 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? Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-475314 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? Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-476505 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; } Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-476508 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. Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-476599 Share on other sites More sharing options...
Barand Posted February 26, 2008 Share Posted February 26, 2008 It's in the gd extension Link to comment https://forums.phpfreaks.com/topic/92677-fill-multiple-arrays-from-mysql-and-then-loop-together/#findComment-476792 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.