What I'm trying to do is a drag/drop order setup. I have the jQuery setup to send the serialized job to my php script, but for some reason it is not updating. I have an echo statement that is showing me that the order of objects is correct:
ID = 2 Counter = 1
ID = 1 Counter = 2
This also means the function is being called properly, but it does not seem to be actually updating the table, the rest of my inserts/updates work fine, so it isn't the connection.
The function:
public function set_member_order($OrderArray) {
$query = $this->db->prepare(
"UPDATE
`member`
SET
`sort` = :sort
WHERE
`member_id` = :member_id");
$sort = 0;
$member_id = 0;
$query->bindValue(':sort', $sort);
$query->bindValue(':member_id', $member_id);
$counter = 1;
foreach ($OrderArray as $member_id) {
$sort = $counter;
echo "ID = ".$member_id." Counter = ".$sort. "<br />";
$query->execute();
$counter ++;
}
}
I must be missing something, as this should be fairly simple, but I can't pin it down. When I run it and check the data it says the sort order is still 1,1 and 2,2 (the default). I'm also sure the IDs are correct as I pulled them from the database to get them in the first place.
$rows = $query->rowCount();
Is also showing 0 rows effected on each row, when it should be updating, not sure why it's not hititng the database, did I bind them incorrectly? Casting them as int, and using PDO::PARAM_INT did not help either. The only two member_ids in this table are 1 and 2. The query is also valid if I run it manually and input values by hand.
EDIT: I tried to change the member_id initialization to
$member_id = 1;
and it set the member_id of 1 to sort 0, which really makes no sense to me.
$query->execute()call. Maybe you're creating a unique key conflict when you (temporarily) have1,1and2,1in the table.