0

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.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by vibhaJ
0
$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')";

echo $query;

$result = mysql_query($query);

Echo the prepared query string before executing it. Then copy it, run in phpmyadmin. Find out the error there and then correct your php code.

0

You forget mysql_query function before while.

<?
	$sql="SELECT * FROM registered_members WHERE firstname LIKE '".$q."%' OR lastname LIKE '".$q."%'";
	$rs = mysql_query($sql);
	While($row = mysql_fetch_array($rs)){
	$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')");
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.