0

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. :)

5
  • How about maintaining a table containing the track of the users (like how many and which rows they have been assigned.) Just like User1 - 10, User2 - 20 and so on.. Just fetch the last row and track which was the row updated lastly and then again follow the procedure.. Hope you are getting it.. Commented Apr 12, 2013 at 5:57
  • ahhh.. can you explain a bit over this ? Commented Apr 12, 2013 at 6:39
  • Think like this.. User one gets in.. You insert the data in the table that user1 has been assigned to 10th row (this means 1-10 according to your constraint).. then user2 gets in.. You insert the data that user2 has assigned to (11-20).. Now on the other day, user1 comes back, you first check the last row assigned (say, 50th) then you assign 51-60 to user1 and put it into the table. Commented Apr 12, 2013 at 6:43
  • yea .. but how thats the issue. i can't get over its logic :( Commented Apr 12, 2013 at 7:02
  • Ok.. Let me build some pages for you.. I'll get back with my answer... Commented Apr 12, 2013 at 9:23

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

i will update you soon, going to implement now.. can you message me your gtalk id ?
Also, does this code says: that each login user will get different data and no same data will be given to different user ?? also , it will give daily new next data to everyone.
Yes, This code will assure you that no same data will be assigned to different users, and it will always go on next data with the count of every user.. pandya.hiren.a is my gtalk id..
Its not working in my code.. do you think its a issue of MySQLi ? as i am using mysql in whole code ?
No. That can't be MySQLi problem. But still, As I said, change the code accordingly, I am not assuring you that the same code will work in your project. This is just to clear out implementation of the logic. Rest, the coding is upto you..
|
0

You don't need a extra framework. Simply done with php 'n' sql! Why you don't save the last edited lines (linenumbers) in a extra SQL-Table? Maybe with the username / userid.

2 Comments

actually my db will be lot big, hence i need some reliable option to make it automatic.
You can specify a query which will automatically delete some of the rows which are of no use after some time.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.