First, thanks in advance for any help.
Here's my issue.
I've read through tons of similar problems here but I don't think I'm understanding this enough to make this work.
I have an XML file such as:
<unitlist>
<unit>
<iterator>0</iterator>
<route>2</route>
<rt_name>'Riverfront Streetcar'</rt_name>
<name>457</name>
<lat>2956.21014</lat>
<lng>-9004.62839</lng>
<bearing>2.14501</bearing>
<car_type>'RTA Street Cars'</car_type>
<speed>16.57122</speed>
<GMT>043432</GMT>[/indent]
</unit>
<unit>
<iterator>1</iterator>
<route>10</route>
<rt_name>'Tchoupitoulas'</rt_name>
<name>250</name>
<lat>2958.0927</lat>
<lng>-9005.28724</lng>
<bearing>1.532399</bearing>
<car_type>'RTA Buses'</car_type>
<speed>0.6904677</speed>
<GMT>104620</GMT>[/indent]
</unit>
</unitlist>
What I want to do is, for each <unit>, import all attributes of that unit (iterator,route,rt_name, etc, etc, etc) into my mySQL database. My problem is that, all it's doing is importing the same attributes of the first <unit> the number of times that <unit> exists. In this example, it's importing the same information from the first <unit> twice, as two records/rows. If I had 90 <unit>s, it would import 90 identical records.
Here's my code:
foreach($unitlist->unit as $unit) {
//insert into database
mysql_query("INSERT INTO businfo (iterator,route,rt_name,name,lat,lng,bearing,car_type,speed,GMT)VALUES (\"$iterator\",\"$route\", \"$rt_name\", \"$name\", \"$lat\", \"$lng\", \"$bearing\", \"$car_type\", \"$speed\", \"$GMT\")")
or die(mysql_error());
}
Can anyone explain what I'm doing wrong?
Thanks again for the help!
- dan -