Jump to content

Fill multiple arrays from mysql and then loop together.


beckjoh

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.