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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update multiple records ??

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
I have the following table:
Id priority
1 3
2 5
3 7
4 2
5 1
6 6
7 4

$pr = 3;
$query = mysql_query("select * from mytable ORDER BY priority");
$num = mysql_num_rows($query);
for ($i=1;$i<$num+1;$i++){
if ($i>=$pr){
$j = $i + 1;
$SQL=&quot;UPDATE mytable SET priority ='$j' where priority = '$i'&quot;;

am trying to update the table by adding 1 to the selected rows then 3 will be 4 and 4 will be 5 etc…, but it won't work.
Thanks in advance
 
Thank you sleipnir214,
But I don't want to update the records their values are: 1 , 2 and 3, I need to update the values of the records from 4 to the end of the table
 
Thanks again,
and i tried :

$old = 3;
$new = 2;

$SQL = mysql_query(&quot;UPDATE mytable SET priority = priority +1 and priority between $new and $old&quot;);
$update = mysql_query(&quot;UPDATE mytable SET priority = $new where id = 4&quot;);
it works but it updates the rest of IDs to 0 ??
 
This is correct behavior for this query:

UPDATE mytable SET priority = priority +1 and priority between $new and $old


MySQL is interpreting it as

UPDATE mytable SET priority = ((priority +1) and (priority between $new and $old))

The lefthand side of the assignment statement is being interpreted as a logic operation. The column priority then gets the value of that assigment. In the cases where priority is not between $new and $old, the logical operation evaluates to zero.

Simple SQL queries take the general form of: <SOME ACTION> WHERE <SOME CONDITIION>. You might try the query:

UPDATE mytable SET priority = priority +1 WHERE priority between $new and $old Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top