• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matching data from 2 table with validation date

#1
At this time I have data from the database, results of the join data table users and table campaigns, like this :

ID
001
005
008

and I have data from table incomes, like this :

id       name      date
1        001        2018-10-10
2        005        2018-10-10
3        008        2018-10-10
4        001        2018-10-11

how to check the results of the join data in table incomes?

if the data ID is not the same as the data name on 2018-10-11, the results will be obtained :

ID
005
008

The question: what query should I use and what method do I need to apply in the controller / view. if the masters here are willing to include with simple code it is very very valuable to me.

thank you, greetings coding.
Reply

#2
@DELE,

You need to determine what join you want (https://www.cloudways.com/blog/wp-conten...ysql-1.png )

This might work for you...

select ucj.id
from users_campaigns_join ucj
inner join incomes i on i.id = ucj.id
where i.date = '2018-10-10'
Reply

#3
(02-06-2019, 08:45 PM)php_rocs Wrote: @DELE,

You need to determine what join you want (https://www.cloudways.com/blog/wp-conten...ysql-1.png )

This might work for you...

select ucj.id
from users_campaigns_join ucj
inner join incomes i on i.id = ucj.id
where i.date = '2018-10-10'

from users_campaigns_join ucj // this is not a table but results from a combination of user tables and campaign tables, are you sure this way?
Reply

#4
@DELE,

users_campaigns_join could be a view or a query (subset of data).  I just used the name to represent the data.

Like below...
PHP Code:
select ucj.id
from users_campaigns_join_view ucj
inner join incomes i on i
.id ucj.id
where i
.date '2018-10-10' 
Reply

#5
(02-07-2019, 05:35 PM)php_rocs Wrote: @DELE,

users_campaigns_join could be a view or a query (subset of data).  I just used the name to represent the data.

Like below...
PHP Code:
select ucj.id
from users_campaigns_join_view ucj
inner join incomes i on i
.id ucj.id
where i
.date '2018-10-10' 

I do not really understand your point.

this is the code that I use to produce (what you call) ucj.
PHP Code:
public function test1()
{
    $this->db->select();
    $this->db->from('users');
    $this->db->join('campaigns''campaigns.id = users.id');
    $res $this->db->get();

    foreach ($res->result() as $key) {
 
      echo $key->ID.'<br>';
    }
}

// Results
// 00001
// 00005
// 00008 

how to implement your method using this method?
PHP Code:
public function test2()
{
    $this->db->select();
    $this->db->from('???'); // how to implement your method here?
    $this->db->join('incomes''incomes.id = ???.id');
    $this->db->where(???);

    $res $this->db->get();
    foreach ($res->result() as $key) {
 
      echo $key->ID.'<br>';
    }
}

// So the results can be like this
// 005
// 008 
Reply

#6
@DELE,

I prefer to use the query bindings feature ( https://www.codeigniter.com/userguide3/d...y-bindings ).   This gives me more flexibility to write my own queries and the binding feature automatically escapes the variables for me.  So my code would look like...

PHP Code:
$sql "select ucj.id
from users_campaigns_join_view ucj
inner join incomes i on i.id = ucj.id
where i.date = ?"
;

$this->db->query($sql, ['2018-10-10']); 
Reply

#7
I understand the meaning of the flow of your code, which I am confused is the users_campaigns_join_view.

because what I know is that it must contain the name of the database table that will be joined.
Reply

#8
@DELE,

Are you familiar with views? Not CI views but database views?
Reply

#9
(02-08-2019, 10:19 AM)php_rocs Wrote: @DELE,

Are you familiar with views?  Not CI views but database views?


thank you very much for your help, my knowledge in the database is still ordinary. but now I have got what I want.

I look for differences between two tables.

thank you again for your help.


PHP Code:
public function test()
{
 
   $t $this->db->query("
        SELECT *
        FROM ( 
            SELECT users.id
            FROM users
            INNER JOIN campaigns
            ON users.id = campaigns.id
        ) users_campaigns
        WHERE NOT EXISTS ( 
            SELECT *
            FROM incomes
            WHERE users_campaigns.id = incomes.income_campaign
            AND incomes.income_date = '2019-02-02'
        )
    "
);

 
   print_r($t->result());
}

// RESULTS
// ID
// 005
// 008 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.