accent problem jquery.sqlbuilderdemo-0.06.js

Hi,

I'm using this plugin sqlbuilderdemo-0.06.js
http://plugins.jquery.com/project/SQL_QUERY_BUILDER
and when displaying data from the database all accent become a question mark
(ISO 8859-1 (Latin-1) Characters List - for french)
I'm looking for a way to fix it.

Thanks
LVL 28
lenamtlAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
>where should I add : header("Content-Type: text/plain; charset=ISO-8859-1");

Good to put it before any command sending data out in the query.php file.
I see only echo and die so why not on the first line ? (second
<?

header("Content-Type: text/plain; charset=ISO-8859-1");

/*this query takes sql clause taht sends an html table back with the data..*/

$querytorun=stripslashes($_POST['querytorun']);

Open in new window

0
 
leakim971PluritechnicianCommented:
and you are using the same encoding everywhere (database, code and html) ?
0
 
lenamtlAuthor Commented:
Yes, all other page display correctly, the DB is set to latin1

This is only when using this javascript that contain some ajax that does not display special characters correctly. I can't change the entire site and db to UTF-8.
application and that was fixing the problem

<?php
   mb_convert_encoding("té trö lôl uè mdr!!!1", "UTF-8", "ISO-8859-1");
 ?>

or

<?php
echo iconv("ISO-8859-1","UTF-8","té trö lôl uè mdr!!!1");
?>


But using this javascript sqlbuilderdemo I don't know where to put this piece of code...to make it work.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
lenamtlAuthor Commented:
If you want to test you can get the package
http://plugins.jquery.com/node/9163/release
you will need to download version 0.06 and 0.05 cause query.php is missing in the 0.06 version.

I want to use it in my custom PHP/MySQL web application.

Thanks
0
 
leakim971PluritechnicianCommented:
Je ne pense pas que tu puisses utiliser mb_convert_encoding et iconv parce que le code PHP reçoit la requête toute faite.

You can try to edit query.php line 5 :

We replace :
$querytorun=stripslashes($_POST['querytorun']);

By:
$querytorun = stripslashes( mb_convert_encoding( $_POST['querytorun'] ), "UTF-8", "ISO-8859-1");
0
 
lenamtlAuthor Commented:
Hi,

Ok I have try your solution and I'm getting these errors
Warning: Wrong parameter count for mb_convert_encoding()
Warning: Wrong parameter count for stripslashes()
0
 
leakim971PluritechnicianCommented:
Better :


$querytorun = stripslashes( mb_convert_encoding( $_POST['querytorun'] , "UTF-8", "ISO-8859-1") );

Open in new window

0
 
lenamtlAuthor Commented:
This time no error but still accent problem :(
0
 
lenamtlAuthor Commented:
Still need a solution for this any clues?
0
 
leakim971PluritechnicianCommented:
Did you try a simple ajax call to return some data the simple way from the database to check if your get the question marks too?
0
 
lenamtlAuthor Commented:
Sorry my ajax knowledge is very limited..
If I check in the DB or display DB table using PHP the record are displayed correcty
for example for the word "Hôpital" if I check in the DB or in PHP request I can see "Hôpital"

When displaying  "Hôpital" using this jquery plugin it's displaying  "H?pital"



0
 
leakim971PluritechnicianCommented:
No worries,

create a php page getting data from the database and return it for example the field having : "Hôpital"


<?PHP

// stuff to connect to database
$sql = "SELECT myField FROM myTable WHERE ID = someIDWillReturnHopital";
// run the query
// get the field

print $hopital; // should print hôpital (from the database)

?>

Open in new window

0
 
leakim971PluritechnicianCommented:
and check with a simple ajax call :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript"> 
	$(document).ready(function() {
		$.get("mySimplePHPScript.php", function(data) {
			$("input").val( data );
		});
	});
</script> 
<body> 
<input  />
</body> 
</html>

Open in new window

0
 
lenamtlAuthor Commented:
I'm confused...

You code looks like a basic php request...
It is not ajax call?

0
 
lenamtlAuthor Commented:
oups ok you have posted the second part :)
0
 
leakim971PluritechnicianCommented:
this is for testing purpose, to be sure we get valid char from database with a simple ajax call before using the plugin

we have two page/code :

a php script return the field from the database (you should select a row and a field with "hôpital")

a html, client side page calling the previous script and put the result ("hôpital" or "h?pital") in a textbox
0
 
leakim971PluritechnicianCommented:
>oups ok you have posted the second part :)

;-))
0
 
lenamtlAuthor Commented:
Ok I will test that, I will need to set $hopital variable to make it work.

I'm going to lunch and II will be back in one hour
0
 
leakim971PluritechnicianCommented:
>Ok I will test that, I will need to set $hopital variable to make it work.

yes from the database,
ok, see you later
0
 
lenamtlAuthor Commented:
I got this
 H¿al
for
Hôpital


0
 
leakim971PluritechnicianCommented:
change simple ajax call page to :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript"> 
	$(document).ready(function() {
		$.get("mySimplePHPScript.php", function(data) {
			$("input").val( data );
		});
	});
</script> 
<body> 
<input  />
</body> 
</html>

Open in new window

0
 
lenamtlAuthor Commented:
same result

0
 
leakim971PluritechnicianCommented:
could you confirm collation for the database table latin1_general_ci ? I was assuming the charset is latin1.
0
 
leakim971PluritechnicianCommented:
Put this in you php script :

header("Content-Type: text/plain; charset=ISO-8859-1");

It work for me :
<?PHP
    $link = mysql_connect("localhost", "root", "password");
    mysql_select_db("database", $link);
    
    $sql = "SELECT * FROM latinos";
    $result = mysql_query($sql);
 
    if($row = mysql_fetch_array($result)) {
        $hopital = $row[0];
    }
   
    header("Content-Type: text/plain; charset=ISO-8859-1");
    print $hopital;

?>

Open in new window

hopital.jpg
0
 
lenamtlAuthor Commented:
Ok your example finally work.
Now to make this work with the script where should I place the
wherw should I add
header("Content-Type: text/plain; charset=ISO-8859-1");

and what else should I do with these files
reports.php (my report page)
query.php
reportshandler.php
0
 
lenamtlAuthor Commented:
Ok fantastic it's work ok now!
Thanks you so much!
0
 
lenamtlAuthor Commented:
Thanks for your patience!
0
 
leakim971PluritechnicianCommented:
You're very welcome! Thanks for the points! Have a nice week-end!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.