yea its sending the ajax/jquery request that is messing me up right now! just cant figure it out. this is the javascript <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } Code (markup): php i had to revert back to when it was working... that why the query is old. if you could maybe throw a suggestion out there. i love what javascript does but i hate trying to get it to work. im at the "please kill me" phase right now! and its way too early in the day for that!! if(!$db) { // Show error if we cannot connect. echo "ERROR: Could not connect to the database."; } else { if(isset($_POST['queryString'])) { $queryString = $db->real_escape_string($_POST['queryString']); if(strlen($queryString) >0) { $query = $db->query("SELECT s_last, s_city FROM table_student WHERE s_last LIKE '$queryString%' or s_city LIKE '$queryString%'"); if($query) { // While there are results loop through them - fetching an Object (i like PHP5 btw!). while ($result = $query ->fetch_object()) { echo '<li onClick="fill(\''.$result->s_last.'\',\''.$result->s_city.'\');">'.$result->s_last.', ' .$result->s_city.'</li>'; } } else { echo 'ERROR: There was a problem with the query.'; } } else { // Dont do anything. } // There is a queryString. } else { // echo 'There should be no direct access to this script!'; echo $queryString2; }} ?> Code (markup):
what do you mean by messing up?? are you getting JavaScript error? are you not getting data from ajax response? please mention problem so that we can think over it and resolve it..
ok probably no surprise to you i am getting "document.oneone is undefined" out of this. this line $.post("rpc.php",{queryString:""+inputString+"",one:""+document.oneone.value+""},function(data){ Code (markup): this is where the line is at <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php",{queryString:""+inputString+"",one:""+document.oneone.value+""},function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } </script> Code (markup): this is my drop down <select id="oneone" value=""> <option value="s_city">city</option> <option value="s_last">Last</option> <option value="s_first">First</option> </select> Code (markup): this is the where that code is at... <body> <div> <form> <div> Type your county: <br /> <select id="oneone" value=""> <option value="s_city">city</option> <option value="s_last">Last</option> <option value="s_first">First</option> </select> <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" /> </div> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> </form> </div> </body> Code (markup): and i haven't even got here yet to see whats is wrong. <?php $db = new mysqli(); if(!$db) { // Show error if we cannot connect. echo "ERROR: Could not connect to the database."; } else { if(isset($_POST['queryString'])) { $queryString = $db->real_escape_string($_POST['queryString']); $one = $_POST['one']; if(strlen($queryString) >0) { $query = $db->query("SELECT '$one%' FROM table_student WHERE s_last LIKE '$queryString%'"); if($query) { // While there are results loop through them - fetching an Object (i like PHP5 btw!). while ($result = $query ->fetch_object()) { echo '<li onClick="fill(\''.$result->$one.'\');">'.$result->$one.'</li>'; // echo '<li onClick="fill(\''.$result->s_last.'\',\''.$result->s_city.'\');">'.$result->s_last.', ' .$result->s_city.'</li>'; } } else { echo 'ERROR: There was a problem with the query.'; } } else { // Dont do anything. } // There is a queryString. } else { // echo 'There should be no direct access to this script!'; }} ?> Code (markup):
change document.oneone.value HTML: to document.getElementById('oneone').value HTML: or since you are using jQuery $("#oneone").val() HTML:
YOU ARE THE BEST. i knew it was something simple like that but.. im stupid! well i changed the query to look like this $query = $db->query("SELECT $one FROM table_student WHERE $one LIKE '$queryString%' LIMIT 10"); Code (markup): and it works great if my select box is on last (s_last) however does not work if i have it on first (s_first) i get "undefined property stdClass: : (path to rpc.php) on line 22 line 22 looks like this right now echo '<li onClick="fill(\''.$result->s_last.'\');">'.$result->s_last.'</li>'; Code (markup): if i do this on line 22 echo '<li onClick="fill(\''.$result->s_last.'\',\''.$result->s_first.'\');">'.$result->s_last.', ' .$result->s_first.'</li>'; Code (markup): i still get the error but at the bottom i do get the result but i error on s_last. so my question is how do i get this to be able to change by what i am selecting?
you are selecting one column from table and trying to display 2. this is creating problem. I suggest that select only those columns which you have to display. Do this way.. put all fields on paper. put various types of indexes you have created. then make a list of fields to be selected based on what index. and then accordingly write code for each case. once you have written the code, look out places which are common and merge them with parameters. just a little thought process and you are there!
ok i think i understand what you are saying. basically all i want is to be able to search on a few feilds. however i always want first and last name to show in the drop down. so that means my query is going to look like this $query = $db->query("SELECT $one, s_last, s_first, id FROM table_student WHERE $one LIKE '$queryString%' LIMIT 10"); Code (markup): i have been struggling with this for so long i forgot what i wanted! i THINK this is exactly what i want. i am pulling in the id because -- well -- the next question is how do i now execute a search on id that i get in. but this line right now shows when i have city selected in the drop down list and i start typing it show s_last and s_first when click on it, it only fills the box with s_last. echo '<li onClick="fill(\''.$result->s_last.'\',\''.$result->s_first.'\');">'.$result->s_last.', ' .$result->s_first.'</li>'; Code (markup): basically the question is how do i get the auto search to execute what it has found. this is what i was thinking but how would that would if there is more than one element in it? <input type="button" value="Search" onClick="inputter(document.getElementById('inputString').value)"> Code (markup):
any ideas how this can be done? right now i search, in the drop down box show the s_last and s_first when i click on the one i want the s_last gets filled in the box. i would like to do a search on the id of that name. right now i have this echo '<li onClick="fill(\''.$result->s_last.'\',\''.$result->s_first.'\');">'.$result->s_last.', ' .$result->s_first.'</li>'; Code (markup): i would like to when i click on the name for it to show first last name however when i press search for it to send to another php page the id of the first and last name? this is my javascript now <script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php",{queryString:""+inputString+"",one:""+$("#oneone").val()+""},function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup ///////////////////// ///////////////////// function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } /////////////////////////////////////////////// ////////////////////////////////////////////// function inputter(element) { parent.location='1.php?option=s_ladst&id=' + escape(element); } $(document).ready(function() { $('#inputString').keyup(function(e) { if(!e) e = window.event; if(e.keyCode == 13) { inputter(document.getElementById('inputString').value); } } ) } ) //////////////// //////////////// /////////////// </script> Code (markup): this is my html page now <body> <div> <form method="get"> <div> Type your county: <br /> <select id="oneone" value=""> <option value="s_city">city</option> <option value="s_last">Last</option> <option value="s_first">First</option> </select> <input type="text" size="30" value="" autocomplete="off" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" /> <input type="text" size="30" value="" autocomplete="off" id="inputString" onblur="fill();" /> <input type="button" value="Search!" onClick="inputter(document.getElementById('inputString').value)"> </div> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> </form> </div> </body> </html> Code (markup):