onthespot Posted August 11, 2006 Share Posted August 11, 2006 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? Quote Link to comment Share on other sites More sharing options...
raza.shahzad Posted August 11, 2006 Share Posted August 11, 2006 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. Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 11, 2006 Author Share Posted August 11, 2006 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! Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 11, 2006 Share Posted August 11, 2006 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.com/tutorials/129/0.php Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 pmsl sorry dude, ill take a look now m8 Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 also tho, say my profiles are on the end of the address sohttp://mysite.com/username1http://mysite.com/username2http://mysite.com/username3amd 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? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 12, 2006 Share Posted August 12, 2006 I don't understand what your asking. Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 ok sorry its bad grammar by myselfbasically 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 Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 12, 2006 Share Posted August 12, 2006 Assuming the usernames are stored in a db, then you can use a query like:[code]SELECT * FROM users WHERE username LIKE '%$searchterm%';[/code]Then just loop through the result and echo them out with links to the respective profiles. Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 mate im new to php, im not sure how to do what u specified at the end! Quote Link to comment Share on other sites More sharing options...
raza.shahzad Posted August 12, 2006 Share Posted August 12, 2006 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 serverif (!($link=mysql_pconnect($dbhostname,$dbusername,$dbpassword))) { echo ("error connecting to the server"); exit();}// select the databaseif (!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 foundwhile ($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. Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 why thankyou, i now see i was making a big thing out of nothing ;) Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 got a problemive 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? Quote Link to comment Share on other sites More sharing options...
Prismatic Posted August 12, 2006 Share Posted August 12, 2006 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%'"; Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 still the same problem, i had already spotted that error dude! Quote Link to comment Share on other sites More sharing options...
Jocka Posted August 12, 2006 Share Posted August 12, 2006 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 Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 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 Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 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! Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 anyone ;)? Quote Link to comment Share on other sites More sharing options...
Jocka Posted August 12, 2006 Share Posted August 12, 2006 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 foundwhile ($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? Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 12, 2006 Author Share Posted August 12, 2006 absolutely quality mate, thankyou mate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.