PDA

View Full Version : Help with proper while looping


chornbeck
03-14-2006, 09:05 PM
Here's the script:

$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
$_xml .="<markers>\r\n";
while ($roo = mysql_fetch_array($availZIP)) {
$ZIPArr = $roo['ZIP'];
$ZIPQuery = mysql_query("SELECT ZIPCode, FirstName, LastName from owner_zips WHERE ZipCode = $ZIPArr") or die (mysql_error());
while ($rop = mysql_fetch_array($ZIPQuery)) {
$ownerrop = $rop['ZIPCode'];
$availCOORD = mysql_query("SELECT LAT,LNG from coord_db WHERE ZIP = $ownerrop") or die(mysql_error());
while ($rou = mysql_fetch_array($availCOORD)) {
if ($rou["LAT"]) {
$_xml .="\t<marker lat=\"" . $rou["LAT"] . "\" lng=\"" . $rou["LNG"] . "\" html=\"" . $rop['FirstName'] . " " . $rop["LastName"] . "\" label=\"" . $rop["ZIPCode"] . "\" />\r\n";

}
}
}
}
$_xml .="</markers>";
$file= fopen("results.xml", "w");
fwrite($file, $_xml);
fclose($file);
echo "XML has been written. <a href=\"results.xml\">View the XML.</a>";




Currently, this outputs something like:

<marker lat="32.794841" lng="-80.005" html="Donald Smalls" label="29407"/>
<marker lat="32.794841" lng="-80.005" html="Gabriel J. Smith" label="29407"/>
<marker lat="32.794841" lng="-80.005" html="Nathaniel Washington" label="29407"/>
<marker lat="32.794841" lng="-80.005" html="Brice J. Williams" label="29407"/>
<marker lat="32.84885" lng="-79.85773" html="Shelia D. Foster" label="29409"/>
<marker lat="32.73727" lng="-79.95409" html="Wayne Carr" label="29412"/>
<marker lat="32.73727" lng="-79.95409" html="Joshua Eckdish" label="29412"/>
<marker lat="32.73727" lng="-79.95409" html="Brent A. Flickinger" label="29412"/>
<marker lat="32.73727" lng="-79.95409" html="Anne J. Forbes" label="29412"/>


What I want it to do is to output all the names that match the ZIP Code and LAt/Lon in each <marker>.

For instance, the marker that represents "29412" above (the last four), would look like this:

<marker lat="32.73727" lng="-79.95409" html="Wayne Carr, Joshua Eckdish, Brent A Flickinger, Anne J Forbes" label="29412"/>

I guess it's OK if that same line gets put into the xml file multiple times, in this case four times... (I'm sure it probably will in this instance...)