Accurax Posted January 9, 2007 Share Posted January 9, 2007 2 tables in my database, and i need to create a function that will allow a user to search these tables and then display the results in a given order.I'm having serious trouble finding a tutorial on how to achieve this ...... please, does anyone know of a half decent tutorial that i can follow as i could really do with learning how to achieve this asap.If you could post any links you have id really really appreciate it... thankuyyou guys Link to comment https://forums.phpfreaks.com/topic/33514-need-help-searching-my-database/ Share on other sites More sharing options...
Psycho Posted January 9, 2007 Share Posted January 9, 2007 Well, your description is a little vague.here are some tutorials that may or may not have what you are looking for:http://www.tizag.com/mysqlTutorial/mysqlquery.phphttp://www.developerfusion.co.uk/show/3998/7/If you were to describe the format of your tables and how you want to search them and wheat data you want retrieved., I think we could probably provide the code as well as an explanation of how it works. Link to comment https://forums.phpfreaks.com/topic/33514-need-help-searching-my-database/#findComment-156843 Share on other sites More sharing options...
chronister Posted January 9, 2007 Share Posted January 9, 2007 create a search form. Pass the data to a sql query$query="SELECT * FROM table1, table2 WHERE field1, field2 LIKE '%$searchvar%';this query will select all from the 2 tables where field1 or field 2 is like the string entered in the search box.The % is a wildcard character. %abc% will find 123abc456def , %abc will find 123abc, abc% will find abc456defassuming there is a string in the DB like this 123abc456def Link to comment https://forums.phpfreaks.com/topic/33514-need-help-searching-my-database/#findComment-156848 Share on other sites More sharing options...
Accurax Posted January 10, 2007 Author Share Posted January 10, 2007 Thanks guys,Heres a little more detail ..I have two tables, one holds personal information about a member, and the other holds a link to their avatar, now, i want to create quite a detailed form that allows a user to select various options from drop down menu's.. as well as a keyword match to an individuals profile.I want the script to take the fields selected and match them to users in the database, for exampleSELECT * FROM users WHERE age=26 && musictaste=opera && .... && .. && etc etchowever, i dot want the entire form to have to be completed, id like the script to simplt ignore form fields that were not changed from the dafault, thus allowing a user to tailor their own search parameters.And as i mentioned, id like a full text search, that matched entered strings to any text that appears in several given fields in my table.Then i want to display these results on a webpage... I understand that i need to use LIMIT in order to get results showing accross several pages, and so i need to look into this.As far as results display goes... its simply the avatar and the username linking to each users profile. Link to comment https://forums.phpfreaks.com/topic/33514-need-help-searching-my-database/#findComment-157189 Share on other sites More sharing options...
Psycho Posted January 10, 2007 Share Posted January 10, 2007 Well...When the form is submitted youwill just need to parse the field data to build your query string based upon the fields that have data. Here is one possible example:[code]$sql = "SELECT * FROM users WHERE ";if ($_POST['age']) { $whereAry[] = "age = ". $_POST['age']; }if ($_POST['musictaste']) { $whereAry[] = "musictaste = ". $_POST['musictaste']; }//etc.$whereClause = implode(" AND ", $whereAry);$sql .= $whereClause;[/code]For full-text searching and pagination take a look at the tutorials on this site:[url=http://www.phpfreaks.com/tutorials/129/0.php]MySQL Full-Text Searching with PHP[/url][url=http://www.phpfreaks.com/tutorials/147/0.php]Expanded Pagination[/url] Link to comment https://forums.phpfreaks.com/topic/33514-need-help-searching-my-database/#findComment-157762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.