Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating multiple rows at once

Status
Not open for further replies.

jefargrafx

Instructor
May 24, 2001
273
US
I have a bit of code that I want to change the value of a row for very row in a table based on -1

here's my first stab and I'm confussed at why this doesn't work

$query_allpicSortOrderhigher = db_query("SELECT picSortOrder FROM property_pictures WHERE propid='$propid' and picSortOrder > '$current_picSortOrder' order by picSortOrder");
$count = mysql_num_rows($query_allpicSortOrderhigher);
for($i=0;$i<$count;$i++){
list($picSortOrder) = mysql_fetch_row($query_allpicSortOrderhigher);
$picSortOrder = $picSortOrder;
$picSortOrderlower[$i] = $picSortOrder - 1;
echo "picSortOrderlower ".$picSortOrderlower."<br>";
$query_updatepicSortOrder = db_query("update property_pictures set picSortOrder = '$picSortOrderlower[$i]' WHERE propoid='$propid' and picSortOrder>'$current_picSortOrder'");

}

all the echos are so I can see what's going on

what am I doing wrong?

any help would be great

jef
 
Your variables are not being interpreted because of how you are using single and double quotes (' and "). Look here.
 
i think it's a bit more to it than that,

print_r($picSortOrderlower)

show the array???

jef
 
i may not be understanding what you are trying to achieve but it looks like you are over complicating things.

have you tried just running this query (assuming that your values for propid etc are properly escaped

Code:
update
 	property_pictures
set 
	picSortOrder = picSortOrder - 1
where
	propid='$propid'
	and
	picSortOrder > '$current_picSortOrder'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top