I apologize if this is trivial question. I did search and didn't find an answer to my question so I am posting. Thanks upfront for whoever can help me and Thank you for your time. I am trying to do a simple parse of crime data returned by api (sanfrancisco.crimespotting.org) and running into a snag. Very simple code below.
<?
$url = "http://sanfrancisco.crimespotting.org/crime-data?format=xml&count=5&dstart=2009-04-20";
$reports = new SimpleXMLElement($url, NULL, TRUE);
foreach ($reports-> report as $key => $value)
{
echo '<br />';
echo '<b>Case #:</b> '.$reports -> report['case_number'];
echo '<br />';
echo '<b>Crime type</b> '.$reports -> report['crime_type'];
echo '<br />';
echo '<b>Date/Time:</b> '.$reports -> report['date_time'];
echo '<br />';
echo '<b>Date </b> '.$reports -> report['date'];
echo '<br />';
echo '<b>Time:</b> '.$reports -> report['time'];
echo '<br />';
echo '<b>More Info </b> '.$reports -> report['href'];
echo '<br />';
echo '<br />';
echo '<br />';
}
?>
The api returns 5 reports cause when I test the url in my browser I see 5 report tags returned. Here is the output from my browser.
<reports>
<report case_number="120220205" crime_type="Vehicle Theft" date_time="2012-07-17T23:10:00-07:00" date="Tuesday, Jul 17, 2012" time="11:10pm" lat="37.772441" lon="-122.412422" beat="" href="http://sanfrancisco.crimespotting.org/crime/2012-07-17/Vehicle_Theft/320858">STOLEN AUTOMOBILE</report>
<report case_number="120560807" crime_type="Alcohol" date_time="2012-07-16T13:35:00-07:00" date="Monday, Jul 16, 2012" time="1:35pm" lat="37.783288" lon="-122.408954" beat="" href="http://sanfrancisco.crimespotting.org/crime/2012-07-16/Alcohol/334582">
UNDER INFLUENCE OF ALCOHOL IN A PUBLIC PLACE (ARREST, BOOKED)
</report>
<report case_number="120559850" crime_type="Disturbing the Peace" date_time="2012-07-16T13:00:00-07:00" date="Monday, Jul 16, 2012" time="1:00pm" lat="37.778678" lon="-122.416545" beat="" href="http://sanfrancisco.crimespotting.org/crime/2012-07-16/Disturbing_The_Peace/334575">COMMITTING PUBLIC NUISANCE (ARREST, CITED)</report>
<report case_number="120560653" crime_type="Theft" date_time="2012-07-16T12:35:00-07:00" date="Monday, Jul 16, 2012" time="12:35pm" lat="37.784644" lon="-122.414271" beat="" href="http://sanfrancisco.crimespotting.org/crime/2012-07-16/Theft/334580">PETTY THEFT SHOPLIFTING</report>
<report case_number="120560700" crime_type="Theft" date_time="2012-07-16T12:00:00-07:00" date="Monday, Jul 16, 2012" time="12:00pm" lat="37.78966" lon="-122.400934" beat="" href="http://sanfrancisco.crimespotting.org/crime/2012-07-16/Theft/334581">GRAND THEFT BICYCLE</report>
</reports>
As you can see (above) each report tag has a different case_number attribute (eg 120220205, 120560807 and so on). However, when I load the page this is the output I receive.
Case #: 120220205
Crime type Vehicle Theft
Date/Time: 2012-07-17T23:10:00-07:00
Date Tuesday, Jul 17, 2012
Time: 11:10pm
More Info http://sanfrancisco.crimespotting.org/crime/2012-07-17/Vehicle_Theft/320858
Case #: 120220205
Crime type Vehicle Theft
Date/Time: 2012-07-17T23:10:00-07:00
Date Tuesday, Jul 17, 2012
Time: 11:10pm
More Info http://sanfrancisco.crimespotting.org/crime/2012-07-17/Vehicle_Theft/320858
Case #: 120220205
Crime type Vehicle Theft
Date/Time: 2012-07-17T23:10:00-07:00
Date Tuesday, Jul 17, 2012
Time: 11:10pm
More Info http://sanfrancisco.crimespotting.org/crime/2012-07-17/Vehicle_Theft/320858
Case #: 120220205
Crime type Vehicle Theft
Date/Time: 2012-07-17T23:10:00-07:00
Date Tuesday, Jul 17, 2012
Time: 11:10pm
More Info http://sanfrancisco.crimespotting.org/crime/2012-07-17/Vehicle_Theft/320858
Case #: 120220205
Crime type Vehicle Theft
Date/Time: 2012-07-17T23:10:00-07:00
Date Tuesday, Jul 17, 2012
Time: 11:10pm
More Info http://sanfrancisco.crimespotting.org/crime/2012-07-17/Vehicle_Theft/320858
Since I am using a foreach loop to loop through the returned results, I don't know why the first case is being repeated 5 times, as I understand the foreach loop should automatically increment.