0

I have two tables in my db and it is one to many connection with other as shown below

enter image description here

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");
5
  • 1
    That is a standard join. Didn't you take at least a SQL tutorial or what is the special problem with this case? Commented Dec 19, 2014 at 7:47
  • Have you tried anything? Commented Dec 19, 2014 at 7:47
  • What does your current query look like? Commented Dec 19, 2014 at 7:47
  • 1
    look for LEFT JOIN, INNER JOIN ... mysql.com will be your friend Commented Dec 19, 2014 at 7:48
  • $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" ); Commented Dec 19, 2014 at 7:49

3 Answers 3

1

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'"
Sign up to request clarification or add additional context in comments.

8 Comments

$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" ); I'm using something like this can please edit this?
Looks OK. what is the error message you get? WHERE name = $committee must be WHERE u.name = $committee
am getting error like this Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'state' in 'where clause'' in D:\xampp\htdocs\projects\online-vyapari\business\kvvs.php:19 Stack trace: #0 D:\xampp\htdocs\projects\online-vyapari\business\kvvs.php(19): PDOStatement->execute() #1 {main} thrown in D:\xampp\htdocs\projects\online-vyapari\business\kvvs.php on line 19
That can not be. You do not have any column state in your where statement. The error message must come from an other statement.
yes it is the same. 'state' is from GET method that means the variable $commitee returns 'state'
|
1

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']."'

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.