Announcement

Collapse
No announcement yet.

Tables operations

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tables operations

    Hello to every one!
    I have 3 tables
    tbl_1, tbl_2, tbl_3.
    The first table tbl_1 always has much more items that tbl_2 and tbl_3.
    My issue is that I want to remove all tbl_1 items that are on tbl_2 and the result should be a new table tbl_3.

    Example:
    tbl_1 ={"1", "2", "3", "4", "5"};
    tbl_2 ={"1", "5"};
    The result should be:
    tbl_3 ={"2", "3", "4"};

  • #2
    PHP Code:
    a= {"1""2""3""4""5"};
    b= {"1""5"};
    count Table.Count(b);
    for 
    i,f in pairs  (b) do
      for 
    t,d in pairs  (a) do
            if  
    == d then      
              Table
    .Remove(at);
            
    end
      end
    end
    for nk in pairs(a) do
      
    Input.SetText("Input1"k..","..Input.GetText("Input1"));
    end 

    Comment


    • #3
      Thank you for the reply.
      Your code helped me a lot!

      My issue is : the a table is the list of the ids of workers on a database table and the b table is the list of ids of some workers that have not worked that day and should be removed...
      The code that you wrote modifies the main table a, so after every request the list of total workers should be re generated(a query on the database will be made and may slow the app), but at least for now I have a solution.

      Comment


      • #4
        ok let us make a modification

        PHP Code:
        a= {"1""2""3""4""5"};
        b= {"1""5"};
        c=a  --let us copy the main table to play free with the new one !!
        count Table.Count(b);
        for 
        i,f in pairs  (b) do
          for 
        t,d in pairs  (c) do
                if  
        == d then      
                  Table
        .Remove(ct);
                
        end
          end
        end
        for nk in pairs(c) do
          
        Input.SetText("Input1"k..","..Input.GetText("Input1"));
        end 
        now we will not effect table a
        is this solve ??

        Comment


        • #5
          Thank you both

          Comment


          • #6
            Originally posted by claus707 View Post
            My issue is : the a table is the list of the ids of workers on a database table and the b table is the list of ids of some workers that have not worked that day and should be removed...
            The code that you wrote modifies the main table a, so after every request the list of total workers should be re generated(a query on the database will be made and may slow the app), but at least for now I have a solution.
            if you load table 'tbl_1' from a database query
            why do not you do this task on that database query which is the most efficient way

            you can make it with a sql query something like below

            Code:
            select * from table_a left join table_b on table_a.worker_id = table_b.worker_id where table_b.worker_id is null;
            so , result of this query will be 'tbl_3' and you do not have to make another query for 'tbl_2' as well

            and there is no need to loop through those two Lua tables
            amsplugins.com Is Closed.

            Facebook Page

            Comment


            • #7
              Originally posted by reteset View Post
              if you load table 'tbl_1' from a database query
              why do not you do this task on that database query which is the most efficient way

              you can make it with a sql query something like below

              Code:
              select * from table_a left join table_b on table_a.worker_id = table_b.worker_id where table_b.worker_id is null;
              so , result of this query will be 'tbl_3' and you do not have to make another query for 'tbl_2' as well

              and there is no need to loop through those two Lua tables
              wonderful !!
              a master solution
              thanks a lot

              very powerful solution !!

              Comment

              Working...
              X