简体   繁体   English

每位使用者的php限制检视

[英]php limit view per one user

First i must say this my second question (first was closed becouse i did not explain my question very good) 首先,我必须说这是我的第二个问题(第一个被关闭,因为我没有很好地解释我的问题)

I am building databse that should be used by our 50-60 employes. 我正在建立应由50-60名员工使用的数据库。 In our base we have many customers (1row = 1customer). 在我们的基地中,我们有许多客户(1行= 1个客户)。 Idea is when employe open page, it should display one customer, but if another employe open same page it should show another customer (i want to avoid situations if 2 employe press refresh button at the same time, the page sould not display same customer. 想法是当雇员打开页面时,它应该显示一个客户,但是如果另一个雇员打开同一页面,则应该显示另一个客户(我想避免如果2个雇员同时按下刷新按钮的情况,该页面将不显示同一客户。

i have this php code for getting data out of base, but if i push refresh on same time it will give me same result on 2 PC. 我有这个php代码,用于获取基本数据,但是如果我在同一时间推送刷新,它将在2 PC上给我相同的结果。 How can i avoid that 我如何避免这种情况

In table telesales_anc i have column 'Lock_ID' and php update it with '1' when page is open 在表telesales_anc中,我有“ Lock_ID”列,当页面打开时,php用“ 1”更新它

Is there any function that 'hold' the connection to the row or something like that? 是否有任何功能“保持”该行的连接或类似功能? I try to google it but i only find some solution with timer (but i think this is a bad idea, and still 2 emlpoyes can open in same time) 我尝试用谷歌搜索它,但我只找到一些带有计时器的解决方案(但我认为这是个坏主意,仍然可以同时打开2个Emlpoyes)

$MSISDN = "SELECT MSISDN FROM telesales_anc WHERE Lock_ID != 1 LIMIT 1";
$result = $mysqli->query($MSISDN);

while ( $row = $result->fetch_assoc() ) {
$IDcheck = "SELECT ID FROM telesales_anc WHERE '{$row['MSISDN']}' = MSISDN";
$result_IDcheck = $mysqli->query($IDcheck);

while ( $row = $result_IDcheck->fetch_assoc()) {
$lock_ID = "UPDATE telesales_anc SET Lock_ID = 1 where '{$row['ID']}' = ID";
$result_ID = $mysqli->query($lock_ID);

}}

I add a usleep() for a very short time to wait other users lock and a small change at the 2nd sql AND Lock_ID!=1 so if other user locked it you wont fetch this one, please be aware that you need some loops for retries to fetch unlocked one 我在很短的时间内添加了usleep()来等待其他用户锁定,并在第二个sql AND Lock_ID!=1处进行了少量更改,因此如果其他用户锁定了它,则您将无法获取此代码,请注意,您需要一些循环重试以获取解锁的

$MSISDN = "SELECT MSISDN FROM telesales_anc WHERE Lock_ID != 1 LIMIT 1";
$result = $mysqli->query($MSISDN);

usleep(rand(100000,300000)); // we are sleeping randomly between 0.1 - 0.3 seconds for waiting the other users lock
while ( $row = $result->fetch_assoc() ) {
    $IDcheck = "SELECT ID FROM telesales_anc WHERE '{$row['MSISDN']}' = MSISDN AND Lock_ID != 1";
    $result_IDcheck = $mysqli->query($IDcheck);

    while ( $row = $result_IDcheck->fetch_assoc()) {
        $lock_ID = "UPDATE telesales_anc SET Lock_ID = 1 where '{$row['ID']}' = ID";
        $result_ID = $mysqli->query($lock_ID);

}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM