proctk Posted March 1, 2008 Share Posted March 1, 2008 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 https://forums.phpfreaks.com/topic/93867-query-not-working/ Share on other sites More sharing options...
revraz Posted March 1, 2008 Share Posted March 1, 2008 I have posted a checkunique function, you can search for it using my name as the author. Link to comment https://forums.phpfreaks.com/topic/93867-query-not-working/#findComment-481055 Share on other sites More sharing options...
proctk Posted March 2, 2008 Author Share Posted March 2, 2008 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 https://forums.phpfreaks.com/topic/93867-query-not-working/#findComment-481274 Share on other sites More sharing options...
proctk Posted March 2, 2008 Author Share Posted March 2, 2008 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 https://forums.phpfreaks.com/topic/93867-query-not-working/#findComment-481306 Share on other sites More sharing options...
proctk Posted March 2, 2008 Author Share Posted March 2, 2008 This is what the echo of $value returns 571326178 which is 5,7,13.26,178 If I replace the variable with the number 5 then the value I want omitted is gone. for some reason the foreach is not doing the trick Link to comment https://forums.phpfreaks.com/topic/93867-query-not-working/#findComment-481324 Share on other sites More sharing options...
redarrow Posted March 2, 2008 Share Posted March 2, 2008 use a for loop then.... Link to comment https://forums.phpfreaks.com/topic/93867-query-not-working/#findComment-481329 Share on other sites More sharing options...
proctk Posted March 2, 2008 Author Share Posted March 2, 2008 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 https://forums.phpfreaks.com/topic/93867-query-not-working/#findComment-481799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.