Jump to content

code compare


cypher86

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/295157-code-compare/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1507847
Share on other sites

  • 2 weeks later...

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?

Link to comment
https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508318
Share on other sites

 

 

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.

Link to comment
https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508327
Share on other sites

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  :psychic:

Link to comment
https://forums.phpfreaks.com/topic/295157-code-compare/#findComment-1508341
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.