tags:

views:

102

answers:

1
$position .= mysql_insert_id();

$sql = "UPDATE ".$this->table_name."
     SET position = '".$position."'
     WHERE id = '".mysql_insert_id()."'";

When i return $position i get two values 150 and 151. That is current row ID and previous or selected row ID. I just need the previous ROW ID.When i look into my DB i have two values 150151.

This is actually of parent child relationship.

+6  A: 

you just need the previous one (151) ?

then all you have to do is throw away the concatenation operator (.)

$position = mysql_insert_id(); // you get 151

or if you want the 150 , just leave the $position alone :

// $position .= mysql_insert_id();
echo $position; // you get 150

or did I get that wrong ?

andyk
Yes, the .= is adding the mysql_insert_id() to the end of whatever you had in position previously.
AndyMcKenna
It prints me the current row ID, but i wanted the previous ones.. which it has selected.
AndyMcKenna i want the previous position alone.
I was like "Did I really understand the question ?" before I hit the "Answer" button. Heck, I even deleted this once.
andyk
@theband, andyk edited the answer to include how to keep the previous id. You're obviously getting both values at some point because you accidentally concatted them together. It's up to you now to figure out the logic you need to use. Maybe you have 2 variables, $prevPosition and $currPosition. At the end of the loop you could overwrite $prevPosition with $currPosition.
AndyMcKenna
@AndyMcKenna nice pointers.
andyk