Jump to content

Problem with loop query


Scooby08

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.