Jump to content

php search engine


onthespot

Recommended Posts

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

[quote]
// 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.
}

[/quote]

i hope that i have made it easier for you.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

using that code he gave you, just change this:
[code]

// 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();
}
[/code]
to tihs
[code]

// 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();
}
[/code]

maybe that'll help
Link to comment
Share on other sites

ok here, here ya go:
[code]
// 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.
}
[/code]
be sure to replace yoursite.com with your site.. you did see it finds profiles like http://whatever.com/username right?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.