Friend search feature.
Posted: Sat Sep 10, 2011 5:27 pm
Right on my site park profile,
I have made up a search feature for my users to search for people
http://prntscr.com/2zpro
But the issue is that it only works if they put just the frist name or seconds name i need help on how i could get it to make it work for full names.
I used this site http://www.webreference.com/programming ... rch/2.html
The code on that page is,
I have made up a search feature for my users to search for people
http://prntscr.com/2zpro
But the issue is that it only works if they put just the frist name or seconds name i need help on how i could get it to make it work for full names.
I used this site http://www.webreference.com/programming ... rch/2.html
The code on that page is,
Code: Select all
<?php include("auth.php"); ?>
<?php include("sections/database.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<title>Search Friends</title>
<link rel="stylesheet" type="text/css" href="styles.css" media="all" >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include("sections/header.php"); ?>
<?php include("sections/advert.php"); ?>
<div id="container">
<?php
If ($loggedin == 'T')
{
//This code to run if the person is logged in.
echo "<div id=\"headerbar\">Search For a friend! </div>"
;
echo"<h3>Search Contacts Details</h3>
<p>You may search either by first or last name</p>
<form method=\"post\" action=\"searchfriends.php\" id=\"searchform\">
<input type=\"text\" name=\"name\">
<input type=\"submit\" name=\"submit\" value=\"Search\">
</form>";
//echo"<p><a href=\"?by=A\">A</a> | <a href=\"?by=B\">B</a> | <a href=\"?by=K\">K</a></p>";
if(isset($_POST['submit'])){
if(preg_match("/[A-Z | a-z]+/", $_POST['name'])){
$name=$_POST['name'];
//-query the database table
$sql="SELECT uid, firstname, lastname FROM user WHERE firstname LIKE '%" . $name . "%' OR lastname LIKE '%" . $name ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-count results
$numrows=mysql_num_rows($result);
echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>";
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName =$row['firstname'];
$LastName=$row['lastname'];
$ID=$row['uid'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"profile.php?uid=$ID\">" .$FirstName . " " . $LastName . "</a></li>\n";
echo "</ul>";
}
}
else
{
echo "<p>Please enter a search query</p>";
}
}
}
else
{
//The code below is for the people who are not logged in.
echo "<div id=\"headerbar\"> Welcome to Park profile,</div> \r\n"
."
<p>
On this website you are able to meet other people who are also fanatical about going to Theme Parks, and it gives you the chance to meet up with them at your favourite Parks and to share your experience. This site also has the advantage of allowing you to record how often you have been on each ride, so you can boast with accuracy to your friends.
</p>
<p>
Use our site to log onto our new feature system and input what day and Park you are going to, and click to see which of your friend’s will also be there that day so you can either meet up, or avoid them ;)
</p>
<p>
So what are you waiting for? Join the site, and let the fun begin.
</p>
"
;
}
?>
</div>
<?php include("sections/footer.php"); ?>
</body>
</html>