Jump to content


Photo

php search engine


  • Please log in to reply
20 replies to this topic

#1 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 11 August 2006 - 10:20 PM

for my site, i want users to be able to search the names of other users and get on their profile pages! any ideas how i would go about doing this?

#2 raza.shahzad

raza.shahzad
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 11 August 2006 - 10:42 PM

dear friend,
if you are using mySQL to store the profiles of your registered users then you can execute an mysql query using PHP to display the users registered with you. but it depends what database or technology you are using to store the profiles of your users. and the same is what you have not mentioned.

#3 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 11 August 2006 - 10:49 PM

what exactly u need to know? i got the tables on the DB mate, with the profiles, all i want is a search box on my site, where if u type the name/ close to the name in the box and submit, the users profile (already avaliable) will be displayed!

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 11 August 2006 - 11:36 PM

I think this is the third time 3 or 4 days I've posted the link to the same tutorial on searching using php and mysql..........

http://www.phpfreaks...rials/129/0.php

#5 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 12:28 AM

pmsl sorry dude, ill take a look now m8

#6 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 12:30 AM

also tho, say my profiles are on the end of the address so

http://mysite.com/username1
http://mysite.com/username2
http://mysite.com/username3

amd when i search i want the search to search for the profiles using the usernames!

is there anyway it can literally search the profiles on the end of addresses?

#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 12 August 2006 - 12:37 AM

I don't understand what your asking.

#8 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 12:42 AM

ok sorry its bad grammar by myself

basically i want a search engine on my site where u can type in a users username and when u search u will get a list of usernames that are identical or similar to what u typed in! you can then select them and go to their profile page

#9 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 12 August 2006 - 12:44 AM

Assuming the usernames are stored in a db, then you can use a query like:

SELECT * FROM users WHERE username LIKE '%$searchterm%';

Then just loop through the result and echo them out with links to the respective profiles.

#10 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 12:50 AM

mate im new to php, im not sure how to do what u specified at the end!

#11 raza.shahzad

raza.shahzad
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 12 August 2006 - 01:10 AM

dear friend,
the problem is simple and you are making it complicated. just goto a website that offers tutorials for PHP and look for a tutorial that refers to searching through databases. thats it, you will surely find your answer there.
what i asked you initially was about the database you use. if it is MySQL then you can place a form tag for search'ing purpose and put action="abc.php".
then in abc.php you can put the code that produces the result from mySQL database.
suppose that the visitor to your website is looking for a username similar to $username.
then you can put the following in your abc.php file

// connect to the server
if (!($link=mysql_pconnect($dbhostname,$dbusername,$dbpassword))) {
echo ("error connecting to the server");
exit();
}

// select the database
if (!mysql_select_db($database,$link)) {
echo ("error selecting the database");
exit();
}

// search for the requested/required username
$details = "SELECT * FROM dbtablename WHERE username LIKE '%$username%';
if (!($result = mysql_query($details,$link))) {
echo ("no match found".mysql_error());
exit();
}

// print the result if match is found
while ($myrow = mysql_fetch_array($result)) {
echo $myrow['username'];    // here you can print all the profiles you have. $myrow[] is an array and you have to place in [ here ] the values of entities placed in your db table.
}


i hope that i have made it easier for you.

#12 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 12:39 PM

why thankyou, i now see i was making a big thing out of nothing  ;)

#13 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 07:50 PM

got a problem
ive installed that script, this is the form

<form action='profilesearch.php' method=get>
<input name=search type=text value='Enter username' />
<input type=submit name='user' value='Find Player' class=button />
</form></p>

to go with that, ive put all the details into the script about! then when i enter the username into the form, i get a blank screen, and in the url bar, /profilesearch.php?search=Enter+username&user=Find+Player, when i search ! whats wrong?

#14 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 12 August 2006 - 07:57 PM

I noticed one error straight away, on this line:

$details = "SELECT * FROM dbtablename WHERE username LIKE '%$username%';

Replace it with this

$details = "SELECT * FROM dbtablename WHERE username LIKE '%$username%'";

#15 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 08:03 PM

still the same problem, i had already spotted that error dude!

#16 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 12 August 2006 - 08:23 PM

using that code he gave you, just change this:

// search for the requested/required username
$details = "SELECT * FROM dbtablename WHERE username LIKE '%$username%';
if (!($result = mysql_query($details,$link))) {
   echo ("no match found".mysql_error());
   exit();
}
to tihs

// search for the requested/required username
$username = $_GET['search'];
$details = "SELECT * FROM dbtablename WHERE username LIKE '%$username%';
if (!($result = mysql_query($details,$link))) {
   echo ("no match found".mysql_error());
   exit();
}

maybe that'll help

#17 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 08:37 PM

it would now appear im getting the username, so thankyou mate, however, there is no message saying, no profile found if there is no profile/error

#18 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 08:53 PM

also how can i make the results be links to the actual profile pages?? this would be really good if you could provide me with the information!

#19 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 12 August 2006 - 09:29 PM

anyone  ;)?

#20 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 12 August 2006 - 09:34 PM

ok here, here ya go:
// search for the requested/required username
$username = $_GET['search'];
$details = "SELECT * FROM dbtablename WHERE username LIKE '%$username%';
if (!($result = mysql_query($details,$link))) {
   echo ("no match found".mysql_error());
   exit();
}

// print the result if match is found
while ($myrow = mysql_fetch_array($result)) {
echo "<a href='http://yoursite.com/" .$myrow['username'] . "'>" . $myrow['username'] . "</a>";    // here you can print all the profiles you have. $myrow[] is an array and you have to place in [ here ] the values of entities placed in your db table.
}
be sure to replace yoursite.com with your site.. you did see it finds profiles like http://whatever.com/username right?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users