Jump to content

query not working


proctk

Recommended Posts

HI, I'm trying to omit people who are found in the table users from the query, The first query $sqlCheckMember checks to see if the person is a member and if they are get their user_id. The user ID is  stored in an array member_id[]. Which I then use in the query $sqlbuddy to see if that user_id is found in the table buddy link. If there is a match then I want that person omitted from the query hence buddylink.buddy_id != '$foundMemberId'". For some reason its not omitting the found ids. IF I replace $foundMemberId' with a hard value which a match occurs for that person is omitted.  I think the problem is it's not looping correctly.

 

$sqlCheckMember = ("SELECT first_name, last_name, DOB, user_id FROM users WHERE first_name = '$firstname' AND last_name = '$lastname' AND DOB = '$dob'");

$qryCheckMember = mysql_query($sqlCheckMember)or die("$sqlCheckMember Query Error: ".mysql_error()); 

while($parent_find = mysql_fetch_array($qryCheckMember)):
   
$Member_id[] = $parent_find['user_id'];

endwhile;
endforeach;
endforeach;


//Get Current Year
if(isset($_GET['m'])){
$bYear = substr($_GET['m'],0,4);
}else{
$bYear = date('Y');
}

$arrEVENTS = array();
$arrNames = array();

foreach($Member_id as $foundMemberId):


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

echo $sqlbuddy;

$qrybuddy = mysql_query($sqlbuddy)or die("SQL Error: $sqlbuddy<br>" . mysql_error());

endforeach;

Link to comment
Share on other sites

this could be a simpler approach.

 

however its not omitting the siblings found in the table users.

 

if these three values match then dont include

 

(sibling.siblingfirstname != users.first_name AND sibling.siblinglastname != users.last_name AND sibling.siblingdob != users.DOB)

 

 

any ideas why this is not working


$sqlbuddy = "SELECT * FROM users LEFT JOIN buddylink ON users.user_id = buddylink.buddy_id LEFT JOIN sibling ON sibling.owner_id = users.user_id LEFT JOIN children ON children.owner_id = users.user_id LEFT JOIN parent ON parent.owner_id = users.user_id WHERE buddylink.owner_id = '63' OR (sibling.siblingfirstname != users.first_name AND sibling.siblinglastname != users.last_name AND sibling.siblingdob != users.DOB)";

Link to comment
Share on other sites

I'm getting closer

 

I believe this is simpler and a lot cleaner then my first post

the problem is its not removing the values associated with the $value. 

 

any ideas why, when I echo the $value the correct information is displayed.

 

any ideas

 

 

$qryGetFamilyUserIds = "SELECT * FROM users, sibling, children, parent WHERE sibling.siblingfirstname = users.first_name AND sibling.siblinglastname = users.last_name AND sibling.siblingdob = users.DOB AND sibling.owner_id = '63' OR (parent.parentfirstname = users.first_name AND parent.parentlastname = users.last_name AND parent.parentdob = users.DOB AND parent.owner_id = '63') OR (children.childfirstname = users.first_name AND children.childlastname = users.last_name AND children.childdob = users.DOB AND children.owner_id = '63') OR (users.spousefirstname = users.first_name AND users.spouselastname = users.last_name AND users.spousedob = users.DOB)";

$GetFamilyUserIds = mysql_query($qryGetFamilyUserIds)or die("SQL Error: $qryGetFamilyUserIds<br>" . mysql_error());

while ($FamilyUserIds = mysql_fetch_array($GetFamilyUserIds)):

$arrFamilyIds[] = $FamilyUserIds['user_id'].'<br />';

$UarrFamilyIds = array_unique($arrFamilyIds);

endwhile;

/*print_r ($UarrFamilyIds);*/

foreach ($UarrFamilyIds as $value):

echo $value;


$sqlbuddy = "SELECT * FROM buddylink JOIN users ON buddylink.buddy_id = users.user_id WHERE (buddylink.buddy_id <> '$value') AND (buddylink.owner_id = '63')";

/*echo $sqlbuddy;*/

$qrybuddy = mysql_query($sqlbuddy)or die("SQL Error: $sqlbuddy<br>" . mysql_error());

WHILE ($rbuddy = mysql_fetch_array($qrybuddy)) :

//Buddy Birth days

$exbuddyDOB = explode('-',$rbuddy['DOB']);
$curbuddyDOB = $bYear .'-'. $exbuddyDOB[1] .'-'. $exbuddyDOB[2];

$arrEVENTS[$curbuddyDOB] = 1;

//create buddy b-daystring
$arrNamesBuddy[$exbuddyDOB[2].''.$exbuddyDOB[1]] = ('<br /><span style="font-size:8px;">'.$rbuddy['first_name'].' '.$rbuddy['last_name'].'<br/>B-day</span>');


ENDWHILE;
endforeach;
//

Link to comment
Share on other sites

I thought of something like this, where I add a to query to omit the found ids

 

however its not working The query is repeated by the number of values found in the the array.  any thoughts how to prevent this

 

foreach ($UarrFamilyIds as $value):

$exString = ' AND Buddylink.owner_id !='.$value;

$sqlbuddy = "SELECT * FROM buddylink LEFT JOIN users ON buddylink.buddy_id = users.user_id WHERE buddylink.owner_id = '63' '$exString'";



$qrybuddy = mysql_query($sqlbuddy)or die("SQL Error: $sqlbuddy<br>" . mysql_error());

WHILE ($rbuddy = mysql_fetch_array($qrybuddy)) :

//Buddy Birth days

$exbuddyDOB = explode('-',$rbuddy['DOB']);
$curbuddyDOB = $bYear .'-'. $exbuddyDOB[1] .'-'. $exbuddyDOB[2];

$arrEVENTS[$curbuddyDOB] = 1;

//create buddy b-daystring
$arrNamesBuddy[$exbuddyDOB[2].''.$exbuddyDOB[1]] = ('<br /><span style="font-size:8px;">'.$rbuddy['first_name'].' '.$rbuddy['last_name'].'<br/>B-day</span>');

ENDWHILE;
endforeach;

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.