MikeDizzle Posted January 17, 2007 Share Posted January 17, 2007 I have some code that uses simpleXML to parse the contents of a google base xml file. Currently i have it looping thru and echo'ing the desired information. I want to be able to have more control of the data allowing me to sort, filter, and maybe even graph the output.Would it be better to use a MySQL database to store the results or should I use an array? I'm not very comfortable with multideminsional arrays even after reading several tutorials.Here is the code snippet:[color=blue]$xml = simplexml_load_file($file) or die ("Unable to load XML file!");// build the table and display results by looping thru each elementecho "<table>";foreach ($xml->entry As $entry){ // set the namespace for g:children using http://base.google.com/ms/1.0 $ns_g = $entry->children('http://base.google.com/ns/1.0'); // output the desired content echo "<tr>"; echo "<td>"; echo $ns_g->year . " "; echo "</td>"; echo "<td>"; echo $ns_g->make . " "; echo "</td>"; echo "<td>"; echo $ns_g->model . " "; echo "</td>"; echo "<td>"; echo $ns_g->trim . " "; echo "</td>"; echo "<td>"; echo $ns_g->mileage . " "; echo "</td>"; echo "<td>"; echo $ns_g->price; echo "<br />"; echo "</td>"; echo "</tr>";}[/color]Thanks for any advice/instruction you can provide me :) Quote Link to comment https://forums.phpfreaks.com/topic/34600-use-array-or-database-which-way-to-go-from-here/ Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 I guess it all depends how far down the line you want to access this information... if it's a one time thing go with an array, otherwise setup a table to store the information. Quote Link to comment https://forums.phpfreaks.com/topic/34600-use-array-or-database-which-way-to-go-from-here/#findComment-162999 Share on other sites More sharing options...
MikeDizzle Posted January 17, 2007 Author Share Posted January 17, 2007 [quote author=dgiberson link=topic=122838.msg507087#msg507087 date=1169058375]I guess it all depends how far down the line you want to access this information... if it's a one time thing go with an array, otherwise setup a table to store the information.[/quote]It will be a one time thing, becuase the xml file being parsed will be different every time. The information would only be used short term, basicly session length.given the code above, how would you recommend replacing the current echo output with saving the data to an array?Thank you again Quote Link to comment https://forums.phpfreaks.com/topic/34600-use-array-or-database-which-way-to-go-from-here/#findComment-163005 Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 in the foreach() loop$my_array[$i][0] = $ns_g->year;$my_array[$i][1] = $ns_g->make;etc...$my_array[$i][5] = $ns_g->price;$i++some people like to use keys for their arrays, personally i don't care.... Quote Link to comment https://forums.phpfreaks.com/topic/34600-use-array-or-database-which-way-to-go-from-here/#findComment-163007 Share on other sites More sharing options...
MikeDizzle Posted January 17, 2007 Author Share Posted January 17, 2007 thanks again for the help and guidance. much appritiated Quote Link to comment https://forums.phpfreaks.com/topic/34600-use-array-or-database-which-way-to-go-from-here/#findComment-163018 Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 no problemo, anytime Quote Link to comment https://forums.phpfreaks.com/topic/34600-use-array-or-database-which-way-to-go-from-here/#findComment-163036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.