Hello,
i am facing an issue in retrieving data from an array.
I have a table called registered_members, the table contain First_name, and Last_name.
I also have a table called Friends, it contain Friend_ID, Member_ID, Status.
What i did is that in a search box, when someone type a name it automatically retrieve and autofill the name of from registered_members, as in if you type J the script retrieve Jhon.
The code i use is:
$sql="SELECT * FROM registered_members WHERE firstname LIKE '".$q."%' OR lastname LIKE '".$q."%'";
The issue is, this retrieve all names that start with the search letters, i want it to only retrieve the names that are stored as friends also.
I wrote a script that retrieve friend names, which work well. The code is:
$result = mysql_query("SELECT registered_members.firstname,registered_members.lastname,registered_members.member_id,friends.m_id,friends.f_id,friends.restriction FROM registered_members,friends WHERE (m_id=$id AND f_id=member_id AND restriction='green') OR (f_id=$id AND m_id=member_id AND restriction='green')");
I need to retrieve all names that start with J (for example, or any other letter), then from the names i retrieved to retrieve the ones that are freinds.
So here is what i did:
$sql="SELECT * FROM registered_members WHERE firstname LIKE '".$q."%' OR lastname LIKE '".$q."%'";
While($row = mysql_fetch_array($sql)){
$id= $_SESSION['SESS_MEMBER_ID']; //current user ID.
$x_id= $row['member_id'];
$result = mysql_query("SELECT registered_members.firstname,registered_members.lastname,registered_members.member_id,friends.m_id,friends.f_id,friends.restriction FROM registered_members,friends WHERE (m_id=$id AND f_id=$x_id AND restriction='green') OR (f_id=$id AND m_id=x_id AND restriction='green')");
But, this didn't work, it gives me boolen error resources expected to be 1.
Any ideas & help will be much appreciated. Thank you in advance.