I have two different table in phpmyadmin. One is tbl_user
and another is donate
.
Now I want to take the column donation_date
from tbl_user
and all columns from the donate
table. I want to join one column (donation_date
) from tbl_user
table and all cloumns from donate
table, but dont know how to write the query.
In the below code I just wrote the query of donate
table so how can I join the donation_date
from the tbl_user
.
Here is my details of two tables in phpmyadmin.
tbl_user
table :
donate
table:
$db = new PDO('mysql:host=localhost;dbname=mypro_bms','root','');
$statement = $db->prepare(
"insert into donate(passport_ic,blood_group,blood_bag,)
values(:passport_ic, :blood_group, :blood_bag)"
);
3
Answers
Are you looking for… a simple
JOIN
between tablestbl_user
anddonate
?From your schema images, it looks like column
passport_IPC
can be used to join the tables. Then you can choose which columns to return in theSELECT
clause:Looks like Passport_IC is the common column between the two tables?
You really should use be using numeric, indexed columns. But since you have a small DB, this should work:
EDIT: You should give your a tbl_user table a primary key as well. Look into database normalization: https://en.wikipedia.org/wiki/Database_normalization
As you said, you want to take the column donation_date from tbl_user so you will select just the column nedded
tbl_user.donation_date
ans use the following aliasdonation_date
and to get all columns from the donate table you can use this trickdonate.*
, it gets all column