dpmopn8542 2013-04-12 05:53
浏览 44
已采纳

如何在PHP和MySQL中为多个用户动态地从数据库中获取数据

This question is bit complex atleast for me. Well, I am working on a project and need some bit more help..

Actually i have a module , where when 1 user login he get limited data from 1 table and he update its records. That is done !

second thing, the issue : i have 5 user who will login and will work on data.

but no user should get same data, like we have 1000 records.

Then when 1st user login: he get 10 records from 1 - 10. 2nd user login : he get next 10 ; 11- 20. same so on..

and when next day they login ; they get records from 51. because 5 user last day worked on first 50 data records.

My issue is how to achieve that 2 goals ?

do i need a framework for this ?

or it can be done using simple php n sql ?

any support will be helpful for me. :)

  • 写回答

2条回答 默认 最新

  • dongtuliao6760 2013-04-12 10:00
    关注

    Ok. This is just a raw answer to give you a better idea. This is how you will insert the login .

    Consider having a table containing following fields,

    Table Name: Temp_Table

    user, assigned_rows_last_no, date_assigned

    <?php
    $con=mysqli_connect("example.com","hiren","abc123","my_db");
    
    // These things can be included into a single file say config.php and including in every file so that you dont need to specify connection string everytime.
    
    if (mysqli_connect_errno())
     {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
         } 
    
    //This query required to be included into the file, which is exactly after login.php
    
    $sql = mysqli_query($con,"SELECT assigned_rows_last_no FROM Temp_Table ORDER BY assigned_rows_last_no DESC LIMIT 1");
    // This is because I want the last row number assigned to the user.
    
    IF ($sql == 0) // Check whether the return answer is NULL or not.
    {
        // If the result is empty than add new entry of the user with defined row number.
        // Suppose that current username can be retrieved from SESSION and stored into a variable.
    
        $insertquery = mysqli_query($con, "INSERT INTO Temp_Table Values ('" . $username . $"', 10, CURDATE()");
        mysqli_close($con);
    }
    else
    {
        // Select the last entry of row and add 10 to it. Ex. User2 has been assigned to 11-20, table contains 20 in the row of user2, now user3 comes, this query will select the row_no, add 10 and insert again into the table (i.e. value 30 which means 21-30.)
    
        settype($sql, "int");
        $sql = $sql + 10;
        $insertquery = mysqli_query($con, "INSERT INTO Temp_Table Values ('" . $username . $"', '" . $sql . "', CURDATE()");
        mysqli_close($con);
    }
    
    mysqli_close($con);
    ?>
    

    The field Date will help you to recognize the entries of today, so that you can set your logic for "There should be no duplicate entries for the same user on same day"

    Now, Make you own page, which check the above mentioned things, and assign the rows to the users.

    Note: This code will only be able to clear out the logic for you, I am not sure whether it will work in your code without any changes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集