Q
Q
QPrincess2020-01-14 12:02:55
css
QPrincess, 2020-01-14 12:02:55

How to temporarily hide a row from a table?

Several scripts make requests at the same time every second: Each script does a job and then does an UPDATE `data` = '2' How can I temporarily hide the selected row from the table so that other scripts don't stumble upon the same id and do the job again?
SELECT id FROM `post` WHERE `data` = '1' LIMIT 1;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Boris Sviridov, 2019-03-29
@thunder_thurth

with css look towards hover && display: none; also in the direction of position as absolute and relative and random phrases using js can be done.
Ps stop asking for ready-made solutions, try to do it yourself with the above elements, it will be a good practice

K
Kirill Proger, 2019-03-29
@freekirill

1) You have a dog, this picture is done by checking for mouse hovering through JS, for example
2) After the mouse is hovered, we show a block with texts that appears near the dog.
3) When we move the mouse away, the block should be hidden,
i.e. JS is needed, a little html + ccs

F
FanatPHP, 2020-01-14
@QPrincess

To answer the question in the title, this is only possible in mysql 8, when locked using the SKIP LOCKED option.
If the version is different (and if the problem facing the author is solved ) , then options are possible.
For example add a third status, "processing".
That is, the script selects a row, sets status 3, completes processing, and then steaves 2.
Only in this case will blocking make sense, although I still don’t really see what to block here, except for the entire table, and this, as it were, did not slow down the whole process even more. In general, it all depends on the time it takes to process the string.
If the processing is fast, then let them do the work again.
If it’s long, then lock rows with status 2 for reading, select a row, immediately set status 3 to it, unlock all rows, process the received one, set status 2.
Plus, add another field for the status change time and periodically collect those stuck in status 3.
A more viable option ( again, to solve a problem, not a question) - this is each worker working with its own data block. for example, one selects only id's that end in 1, the second - in 2 - and so on. you can come up with a more or less uniform algorithm so that the workers do not interfere with each other, on the same principles that sharding is done on.
Well, the simplest and most reliable is to put a unique identifier on the line, UUID is quite suitable.
Then instead of select + update, you can immediately update (with the condition that used to go to the select)

update table set guid = {$UUID} where ... limit 1;
... много кода ...
update table set .... guid = null where guid = {$UUID};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question