techker Posted January 18, 2012 Share Posted January 18, 2012 hey guys i have this auto complete but it only selects one table..i need it to select 2? SELECT distinct Nom as suggest FROM Etudiant WHERE Nom like('" .$search . "%') ORDER BY Nom i need Nom and Prenom i tryed Nom,prenom but did not work.. Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/ Share on other sites More sharing options...
AyKay47 Posted January 18, 2012 Share Posted January 18, 2012 hey guys i have this auto complete but it only selects one table..i need it to select 2? SELECT distinct Nom as suggest FROM Etudiant WHERE Nom like('" .$search . "%') ORDER BY Nom i need Nom and Prenom i tryed Nom,prenom but did not work.. your query will weed out the duplicate values that are stored in the field "Nom", what exactly do you want your result set to be? Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308919 Share on other sites More sharing options...
techker Posted January 18, 2012 Author Share Posted January 18, 2012 in need the Nom and Prenom first and last name. i go this but it echos onlythe Nom(first name) and searches only half of the database SELECT distinct Nom,Prenom as suggest FROM Etudiant WHERE Nom like('" .$search . "%') And Prenom like('" .$search . "%') ORDER BY Nom Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308921 Share on other sites More sharing options...
AyKay47 Posted January 18, 2012 Share Posted January 18, 2012 SELECT Nom,Prenom FROM Etudiant WHERE Nom like '%$search%' OR Prenom like '%$search%' ORDER BY Nom Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308923 Share on other sites More sharing options...
techker Posted January 18, 2012 Author Share Posted January 18, 2012 cool it looks good but the page freezes up when i start to type..like if it was searching..the database has over 1000 entries.. Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308924 Share on other sites More sharing options...
fenway Posted January 18, 2012 Share Posted January 18, 2012 Then you get to decide... Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308937 Share on other sites More sharing options...
techker Posted January 18, 2012 Author Share Posted January 18, 2012 but could it be that the distinct is faster? Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308940 Share on other sites More sharing options...
AyKay47 Posted January 18, 2012 Share Posted January 18, 2012 but could it be that the distinct is faster? the only reason it would be faster is because it is pulling less results, what you can do is limit the number of results that is returned using the limit keyword. SELECT Nom,Prenom FROM Etudiant WHERE Nom like '%$search%' OR Prenom like '%$search%' ORDER BY Nom LIMIT 100 Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308950 Share on other sites More sharing options...
techker Posted January 18, 2012 Author Share Posted January 18, 2012 true but if the name there lokking for is at the end of the list? Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308974 Share on other sites More sharing options...
techker Posted January 18, 2012 Author Share Posted January 18, 2012 seems to work faster.i will see if it causes a problem thx for the help Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308977 Share on other sites More sharing options...
kickstart Posted January 18, 2012 Share Posted January 18, 2012 Hi I take it this is for an Ajax call? You have a field where they type the name in and for each letter it does an Ajax call to bring back a list of possible matches? If so the first thing I would suggest is to put in a short delay between people typing a letter and it doing the call back to the server. Doesn't need to be a long delay, but 1/4 of a second will stop repeated calls when someone is typing quickly. Ie, when they type a character you set up a Javascript timer to call a function for the ajax call. The first thing that function does is check if the input field contents are the same as they were when the timer was set up, and if not it abandons the Ajax call. Once you do the call and check the database, 1000 rows isn't much to check and shouldn't take that long. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/255294-select-distinct-help-pls/#findComment-1308981 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.