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!! Quote Link to comment 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!! Quote Link to comment 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.