Scooby08 Posted January 4, 2010 Share Posted January 4, 2010 I can't figure out why this loops SELECT statement is only reading the first record?? <?php foreach ($xml->shirts as $shirt) { foreach ($shirt as $color) { $q = "SELECT * FROM shirt_colors WHERE color = '$color->color'"; $r = mysql_query($q) or die(mysql_error()); $dbarray = mysql_fetch_array($r); if (!$row = $dbarray) { $q = "INSERT INTO shirt_colors (color) VALUES ('$color->color')"; mysql_query($q); } else { $q = "UPDATE shirt_colors SET line_sport_type = '$color->color'"; mysql_query($q); } } } ?> Was also wondering if there was a better way to run these queries more effeciently? Thanks to all replies!! Link to comment https://forums.phpfreaks.com/topic/187095-problem-with-loop-query/ Share on other sites More sharing options...
Scooby08 Posted January 4, 2010 Author Share Posted January 4, 2010 Ok I figured out my problem.. I just needed to specify WHERE for my UPDATE.. But I still would like any suggestions on getting the best performance possible for this loop and the queries being ran within.. Thanks again!! Link to comment https://forums.phpfreaks.com/topic/187095-problem-with-loop-query/#findComment-988035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.