Reputation: 543
I have two tables in my db and it is one to many connection with other as shown below
In kvves_units table I will get 'name
' from the GET
Method
now I want to have all value from the kvves_units
and kvves_members
according to the name of the kvves_units
I'm using the code something like this
$kvvesDetails = $conn->prepare( "SELECT u.id, u.name, u.phone, u.email, u.address, m.name, m.designantion, m.phone, m.email, m.imageFROM kvves_units AS u JOIN kvves_members AS m ON m.unit_id = u.id WHERE `name` = $committee");
Upvotes: 0
Views: 62
Reputation: 69440
This is a standard join:
$kvvesDetails = $conn->prepare( "SELECT u.id, u.name, u.phone, u.email, u.address, m.name, m.designantion, m.phone, m.email, m.image FROM kvves_units AS u JOIN kvves_members AS m ON m.unit_id = u.id WHERE name = '$committee'"
Upvotes: 1
Reputation: 1436
Try :
$name = $_GET['name'];
$sql = "Select *from kvves_units as u INNER JOIN kvves_members as m where u.id = m.unit_id and u.name = '".$name."'";
You will get your solution.
Upvotes: 0
Reputation: 1574
Use this SQL
select kvves_units.*,kvves_members.* from kvves_units a join kvves_members b where a.name = b.name and a.name = '".$_GET['name']."'
Upvotes: 1