UD2006
08-25-2009, 08:30 AM
I have this big problem. I have a contact database with 1 table in mysql, 2 groups of people can login and add contacts to the database, each group should not be able to see the contact ifo from the other group unless a share checkbox is clicked.
Well the problem is as followed, in the database I have column called, group_id (1 or 2), when a group logs in and they want to search in the database, display the records in the fields (input text, checkboxes, memofields), I have create this query to do so, but when I click on search I don't get the result I want, it shows the result of the other group, (I double checked the group_id is set correctly), don't where its going wrong.
Here is the query I use:
<?php
//connect to the database
$db=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("contact_database");
//query the database table
$sql="SELECT group_id, contact_name FROM contacts WHERE group_id='1' AND contact_name LIKE \"%$search%\"";
// run the query against the mysql query function
$result=mysql_query($sql) or die("Couldn't execute query");
if ($result)
{
// create while loop and loop through result set
while($row = mysql_fetch_array ($result)){
$contact_name =$row["contact_name"];
$group_id =$row["group_id"];
echo "$contact_name";
echo "$group_id";
}
}
else {
echo "<p>Geef een zoek woord op</p>";
}
?>
Here the form search code:
<form id="searchcontact" method="post" action="search.php" />
<input type="text" class="search2" name="search"/> <input type="submit" name="submit" class="buttons" value="Zoek" />
</form>
Please need help!
Well the problem is as followed, in the database I have column called, group_id (1 or 2), when a group logs in and they want to search in the database, display the records in the fields (input text, checkboxes, memofields), I have create this query to do so, but when I click on search I don't get the result I want, it shows the result of the other group, (I double checked the group_id is set correctly), don't where its going wrong.
Here is the query I use:
<?php
//connect to the database
$db=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("contact_database");
//query the database table
$sql="SELECT group_id, contact_name FROM contacts WHERE group_id='1' AND contact_name LIKE \"%$search%\"";
// run the query against the mysql query function
$result=mysql_query($sql) or die("Couldn't execute query");
if ($result)
{
// create while loop and loop through result set
while($row = mysql_fetch_array ($result)){
$contact_name =$row["contact_name"];
$group_id =$row["group_id"];
echo "$contact_name";
echo "$group_id";
}
}
else {
echo "<p>Geef een zoek woord op</p>";
}
?>
Here the form search code:
<form id="searchcontact" method="post" action="search.php" />
<input type="text" class="search2" name="search"/> <input type="submit" name="submit" class="buttons" value="Zoek" />
</form>
Please need help!