How combine 3 tables
How combine 3 tables
omurlts
Posts: 35Questions: 6Answers: 0
Table: data
-------------------
| id | name |
-------------------
| 1 | Allan |
| 2 | Charlie |
| 3 | Fiona |
| 4 | Richard |
-------------------
Table: call
-------------------
| id | data_id |
-------------------
| 1 | 4 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
-------------------
Table: call_detay
-----------------------------------------
| id | call_id | phone | not |
-----------------------------------------
| 1 | 1 | 111 | detay 1 |
| 2 | 1 | 112 | detay 2 |
| 3 | 1 | 113 | detay 3 |
| 4 | 4 | 111 | detay 1 |
-----------------------------------------
im use editor php libraries. I want to combine 3 tables
for example :
data.id = call.data_id
call.id = call_detay.call_id <--- but there im want last insert (call_detay id 3 )
how im make this datatables library ?
pls give me example code.
This discussion has been closed.
Answers
Use left join to join the tables
https://editor.datatables.net/manual/php/joins
and a where condition to filter records
https://editor.datatables.net/manual/php/conditions
To understand how this works you would need to have some understanding of relational databases and SQL. If you don't I would start with this:
https://www.w3schools.com/sql/
just need simple example !!
There are a couple of simple examples here.
https://editor.datatables.net/examples/index
It doesn't matter if you left join one or a dozen tables. It is always the same!
If that doesn't help you then you'll find a complex example here. It has multiple left joins, some of them are turned into implicit inner joins by checking for NOT NULL in the where clause. Some of the tables left joined aren't even tables but mySql views. You can do whatever you like. This isn't the limit. But one thing is clear: You must understand relational databases and relational data modelling. If you don't you'll be lost.
Here is another posts on inner joins with Editor. Might be relevant to understand the above code.
https://datatables.net/forums/discussion/49891
Alternative approach:
Just post a tested SQL SELECT statement of what you want to achieve. (select will do, no need to provide insert, update and delete statements.) If you provide that anyone with Editor PHP experience should be able to convert it into Editor PHP Syntax.
my json
im just want
mod_cagri_cagrilistesi.durum == mod_cagri_aramalistesi.durum
not want show other
want this json
im try im combination im tried pls help this about
You need to use a where clause. You already have the link from me above. I am not going to write your code. Sorry.
https://editor.datatables.net/manual/php/conditions
bro im just need help im not full write code
im where clasuse added but still not working.
I just want to know where I made the mistake.
As far as I can tell your where clause is in the wrong place. I don't understand why you need the mjoin. Why don't you write your statement in plain SQL and test it? Once you have the SQL working I can take a look and show you how to convert it into Editor PHP syntax.
@rf1234 bro thanks you
pls dont help me
select * from mod_cagri_aramalistesi mca left join mod_cagri_cagrilistesi mcc on mca.id = mcc.arama_id where mca.p_id = 5 and mca.durum = mcc.durum
And this should be the Editor PHP code:
Since you definitely want an inner join I would keep the checking for null values of the key of the dependent table.
I think normally you won't want to have a hardcoded key value in your code like this:
You could simply remove this line and it should still work.
im before write this code
give this error...
sorry but I have no idea what you mean and certainly there is no error message in your post. You can work with this code which seems to have been generated by Editor and test it in MySQLWorkbench or whatever you are using.
You would need to find out what the bound values are :where_1 and :where_2. The debugger also returns this.
Try this:
I added the "false" in the where clause on "durum" to avoid "mod_cagri_cagrilistesi.durum" being escaped as a string.
this working.
this code not working.
->where('mod_cagri_aramalistesi.durum','mod_cagri_cagrilistesi.durum','=', false)
when im added this
->where('mod_cagri_aramalistesi.durum','mod_cagri_cagrilistesi.durum','=', false)
all mod_cagri_cagrilistesi field null coming.
Try this:
Unfortunately you didn't post the content of the bound values as per my request above. Looking at this: AND
mod_cagri_aramalistesi
.durum
= :where_1I assume that this still is being escaped as a string.
Hence I took a look at the docs:
https://editor.datatables.net/manual/php/conditions
section "Complex Usage".
Looks like this only works using an anonymous function. I am using it with an anonymous function in my code as well.
@rf1234 thanks you bro
im tried im try different system.
Updated once again. Since I can't test this stuff with your code I forgot something. But this should now be executable PHP code:
yes this working thank you so much bro...
ok! read the docs ...
Greetings to Turkey!
I wanted to do exactly that
your example I completely solved my job
again thank you very much @rf1234