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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.