Jump to content

query help


proctk

Recommended Posts

Hi I have the below query that links together a bunch of tables that I draw information out of.  The problem I'm having is a person found in the tables 'children', sibling, parent can also be found in the table users.

 

The common link link between 'children', sibling, parent and the table users. is the first name and last name and dob. So if the child or sibling or parent is found in the table users I don't what them included in the search results

 

query code that works without trying to remove matches

 


$sql = "SELECT users.first_name, users.last_name, children.childdob, children.childfirstname, children.childlastname, sibling.siblingdob, sibling.siblingfirstname, sibling.siblinglastname, parent.parentdob, parent.parentfirstname, parent.parentlastname, users.DOB, users.spousedob, users.spousefirstname, users.spouselastname FROM children LEFT JOIN sibling ON sibling.owner_id = children.owner_id LEFT JOIN parent ON children.owner_id = parent.owner_id LEFT JOIN users ON children.owner_id = users.user_id WHERE users.user_id = '63'";

 

 

code that I'm trying to use to omit duplicate entries,  This code is located after the users.user_id = '63'.

Not it does nothing and should be omitting an entry based on the data

 

 

any help is great thank you

AND parent.parentfirstname != users.first_name AND parent.parentlastname != users.last_name AND parent.parentdob != users.DOB

Link to comment
https://forums.phpfreaks.com/topic/92672-query-help/
Share on other sites

I thought that I would take another approach but still having no luck. I believe I'm closer

When I echo the value $parentMember_id all is good. It show what I'm looking

 

when I echo $sqlbuddy the query is looping way to many times. The correct values are showing but its repeating its self.

 

It not omitting the record taht it should. If I replace the variable $parentMember_id with the number it works.

 

any ideas

 

//check if parent is member, if so get user_id
$sqlCheckparentMember = ("SELECT first_name, last_name, DOB, user_id FROM users WHERE first_name = '$parentFname' AND last_name = '$parentLname' AND DOB = '$parentDOB'");

$qryCheckparentMember = mysql_query($sqlCheckparentMember)or die("$sqlCheckparentMember Query Error: ".mysql_error()); 

$parent_find = mysql_fetch_assoc($qryCheckparentMember);
   
$parentMember_id = $parent_find['user_id'];


$sqlbuddy = "SELECT buddylink.buddy_id, buddylink.owner_id, users.user_id, users.DOB, users.first_name, users.last_name FROM buddylink LEFT JOIN users ON buddylink.buddy_id = users.user_id WHERE buddylink.owner_id = '63' AND buddylink.buddy_id !='$parentMember_id' ";

echo $parentMember_id.'<br/>';
$qrybuddy = mysql_query($sqlbuddy)or die("SQL Error: $sql<br>" . mysql_error());
endwhile

[code]

[/code]

Link to comment
https://forums.phpfreaks.com/topic/92672-query-help/#findComment-474915
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.