I asked a similar question yesterday but it's not the same. I have some values that looks like this, and I want to Insert them So that
123,567,287,124,172,846,372,187
And I want it to look like this
id=123 and SortNumber=1
id=567 and SortNumber=2
id=287 and SortNumber=3
And I want to update a table based on this, so something like this
UPDATE char_
SET SortNumber=1
WHERE id=123
Set SortNumber=2
WHERE id=567
Now, I think I can do something like this
$variable=123,567,287,124,172,846,372,187
$anothervariable=$variable = str_replace(",", "\r\n", $variable);
$i=0;
$i++;
mysqli_query(UPDATE char_ SET SortNumber=$i WHERE id=$anothervariable)
But, I'm not sure that the code is 100 correct AND, the variable will be the whole contents and I dont know how I can set a different variable to every line?
explode()functionUPDATEquery you want to obtain is incorrect. You need several update statements, or a single update usingCASE WHEN