I would like to delop a search facility allowing the user to search other user by name, matching users should be listed, each matching user should have a hyperlink labelled"Make Friends", could anybody help me write an ajax code for this, many thanks

I would like to delop a search facility allowing the user to search other user by name, matching users should be listed, each matching user should have a hyperlink labelled"Make Friends", could anybody help me write an ajax code for this, many thanks

Are the users in a database? If so what database type is it?

It would be easier to develop a search page in just PHP and HTML, and then when that is working, you can add the "AJAX" part.

For searching, i would recommend you to look into the Zend Framework. It provides flexible classes for searching. Search for Zend_Search_Lucene

Are the users in a database? If so what database type is it?

It would be easier to develop a search page in just PHP and HTML, and then when that is working, you can add the "AJAX" part.

Hi

Thanks, i have got users in my database, i am using phpmyadmin database, could you advice me of the sample php code that i need to develop then will come back to you regarding the Ajax one, this is how my user database php looks like, any advanced stuff i can use?

<?php
$a = $_POST["username"];
$b = $_POST["password"];
$c = $_POST["email"];
$d = $_POST["telephone"];

$conn = mysql_connect("localhost", "PeterJones", "skssksks");
mysql_select_db("PeterJones");

$result=mysql_query ("INSERT INTO users (username,password,email,telephone) VALUES ('$a','$b','$c','$d')");
mysql_close($conn);

echo "$a Great You have successfully signed up!";

?>

I will really appreciate your help regarding this!

Hi

Thanks, i have got users in my database, i am using phpmyadmin database, could you advice me of the sample php code that i need to develop then will come back to you regarding the Ajax one, this is how my user database php looks like, any advanced stuff i can use?
<?php
$a = $_POST["username"];
$b = $_POST["password"];
$c = $_POST["email"];
$d = $_POST["telephone"];

$conn = mysql_connect("localhost", "PeterJones", "skssksks");
mysql_select_db("PeterJones");

$result=mysql_query ("INSERT INTO users (username,password,email,telephone) VALUES ('$a','$b','$c','$d')");
mysql_close($conn);

echo "$a Great You have successfully signed up!";

?>

I will really appreciate your help regarding this!

PHPMyAdmin is a MySQL administration interface written in PHP. So the database you'd be using is a MySQL database.

I'd recommend getting a book on MySQL (or even SQL in general). It will help a lot with creating the MySQL queries needed for your project(s).

To create the search functionality, first you have to create a search form. The form could be a simple once, with just one input box, for the username. eg:

<form action="search.php">

<label for="username">User Name</label>
<input type="text" name="username" />

<input type="submit" value="Search" />
</form>

The HTML form can be in a PHP page, or HTML page. The form when submitted, will send the form field values to "search.php", defined it the form's action attribute.

In your search.php page, you will receive the value entered by the user for the field "username".

eg:

$username = $_GET['username'];

You will want to take this $username and create an SQL query with it, that will search the database for that value, or similar values.

eg:

$username = $_GET['username'];

$conn = mysql_connect("localhost", "PeterJones", "skssksks");
mysql_select_db("PeterJones");

$result=mysql_query ("SELECT * FROM users WHERE username = '".mysql_real_escape_string($username)."'");
mysql_close($conn);

The above does a search for the exact username entered into the form. ie: "WHERE username = '{value}'".

If you want to search for usernames that have the entered value within them use:

WHERE username LIKE '%{value}%'

Take a look at the mysql_query() documentation for how to list the results from the query:
http://www.php.net/manual/en/function.mysql-query.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.