cypher86 Posted March 7, 2015 Share Posted March 7, 2015 i'm using jquery autocomplete with a remote php script. this code works fine: db_connect(); $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $qstring = "SELECT id,nominativo,indirizzo,telefono,fax,e_mail FROM legale WHERE nominativo LIKE '%".$term."%'"; $result = mysql_query($qstring);//query the database for entries containing the term while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values { $row['nominativo']=htmlentities(stripslashes($row['nominativo'])); $row['indirizzo']=htmlentities(stripslashes($row['indirizzo'])); $row['telefono']=htmlentities(stripslashes($row['telefono'])); $row['fax']=htmlentities(stripslashes($row['fax'])); $row['e_mail']=htmlentities(stripslashes($row['e_mail'])); $row['id']=(int)$row['id']; $row_set[] = $row;//build an array } echo json_encode($row_set);//format the array into json data this one doesn't: $db=db_connect_param(); $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends if($_GET['what']=="legale") $qstring = "SELECT id,nominativo,indirizzo,telefono,fax,e_mail FROM legale WHERE nominativo LIKE ?"; $search="%$term%"; $sql=$db->prepare($qstring); $sql->bind_param('s',$search); $sql->execute(); $sql->bind_result($id,$nominativo,$indirizzo,$telefono,$fax,$e_mail); //build an array while($sql->fetch()) { $row['nominativo']=htmlentities(stripslashes($nominativo)); $row['indirizzo']=htmlentities(stripslashes($indirizzo)); $row['telefono']=htmlentities(stripslashes($telefono)); $row['fax']=htmlentities(stripslashes($fax)); $row['e_mail']=htmlentities(stripslashes($e_mail)); $row['id']=(int)$id; $row_set[]=$row; } echo json_encode($row_set);//format the array into json data*/ what's the difference? the json returned seems the same. Quote Link to comment https://forums.phpfreaks.com/topic/295157-code-compare/ Share on other sites More sharing options...
mac_gyver Posted March 7, 2015 Share Posted March 7, 2015 this one doesn't: telling us what sort of error or symptom you got that leads you to believe the code doesn't work, would help narrow down the problem. the json returned seems the same. if they are not identical, posting both of them would give someone here information upon which to help diagnose the problem. it's also possible that the second code is outputting something prior to the json encoded data, such as some white-space, a php error message. you should be able to check in your browser's debugging console if there are errors or some unexpected/malformed data. Quote Link to comment https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1507847 Share on other sites More sharing options...
cypher86 Posted March 17, 2015 Author Share Posted March 17, 2015 sorry for the double posting. the script does not return any error. echoing the results i don't see any difference. do you need me to post the two results? Quote Link to comment https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508316 Share on other sites More sharing options...
ginerjm Posted March 17, 2015 Share Posted March 17, 2015 1 - do you have error checking turned properly so that errors can be shown to you? 2 - "this one doesn't". Just what does that mean? white screen? no json returned? something else? 3 - and what if $_GET['what'] is not equal to 'legale'? What query are you going to be preparing then? Quote Link to comment https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508318 Share on other sites More sharing options...
cypher86 Posted March 17, 2015 Author Share Posted March 17, 2015 1 - do you have error checking turned properly so that errors can be shown to you? yes 2 - "this one doesn't". Just what does that mean? white screen? no json returned? something else? no error are diplayed, the json is returned and seems identical to the one returned from the first script 3 - and what if $_GET['what'] is not equal to 'legale'? What query are you going to be preparing then? then it returns nothing. since the json is returned i assume that the parameters are correctly set. Quote Link to comment https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508327 Share on other sites More sharing options...
Solution mac_gyver Posted March 17, 2015 Solution Share Posted March 17, 2015 two different people have asked you to tell us what sort of error/symptom or incorrect result you are getting that leads you to believe this isn't working. how do you know it is not working? we are not standing right next to you and can only see the information that you put in your posts Quote Link to comment https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508341 Share on other sites More sharing options...
cypher86 Posted March 17, 2015 Author Share Posted March 17, 2015 i'm so sorry. i don't know what i was testing. now with the code given in the first post works correctly Quote Link to comment https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508346 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.