emptry Posted April 3, 2017 Share Posted April 3, 2017 Hello Freaks, I working on a little snippet, a live search with MySQL. Now i think it could be nice to store/save which searchword the user, did the search on.Example: User search onMy new book Then i want to store that to my databse.The problem is with my script right now, where i trig the ajax on keyup. Then it will store.MMyMy My NMy Ne...... and so on, how can i come around this and only store the hole line ..? Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 3, 2017 Share Posted April 3, 2017 Well, lets see. As I am reviewing the code you posted.... Oh wait, never mind. Quote Link to comment Share on other sites More sharing options...
emptry Posted April 3, 2017 Author Share Posted April 3, 2017 (edited) haha my friend. i havn't made the script, because i dont know how i should make it I can make it so it will store every single letter.. but that's not what i want But here is my code for the live search $(function() { $("#searchword").keyup(function(){ var text = $(this).val(); if (text != ' ') { $('#result').html(" "); $.ajax({ type: 'post', url: 'livesearch.php', data: { 'search': text }, success: function(dataReturn) { $('#result').html(dataReturn); } }); } }); }); And in my PHP $s = mysqli_query($mysql_link, "SELECT * FROM dagenshug_product WHERE product_name LIKE '%".$_POST['search']."%'"); while ($search_result = mysqli_fetch_array($s)) { print_r($search_result['product_name']); } Edited April 3, 2017 by emptry Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 3, 2017 Share Posted April 3, 2017 I can make it so it will store every single letter.. but that's not what i want So what do you want? Forget about the code and just tell us how the search is supposed to work. If every keystroke triggers a search, it's not possible to reliably tell when the input is complete. You can only guess. For example, save the input after a certain delay or when the text field loses focus due to the user clicking somewhere else. Quote Link to comment Share on other sites More sharing options...
emptry Posted April 3, 2017 Author Share Posted April 3, 2017 Hm... that's was my fear.. 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.