Solved

accent problem jquery.sqlbuilderdemo-0.06.js

Posted on 2010-09-20
28
749 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:lenamtl
  • 14
  • 14
28 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33738295
and you are using the same encoding everywhere (database, code and html) ?
0
 
LVL 24

Author Comment

by:lenamtl
ID: 33743160
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
 
LVL 24

Author Comment

by:lenamtl
ID: 33743259
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
 
LVL 82

Expert Comment

by:leakim971
ID: 33743711
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
 
LVL 24

Author Comment

by:lenamtl
ID: 33746637
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
 
LVL 82

Expert Comment

by:leakim971
ID: 33746930
Better :


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

Open in new window

0
 
LVL 24

Author Comment

by:lenamtl
ID: 33752863
This time no error but still accent problem :(
0
 
LVL 24

Author Comment

by:lenamtl
ID: 33806743
Still need a solution for this any clues?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33807965
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
 
LVL 24

Author Comment

by:lenamtl
ID: 33808798
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
 
LVL 82

Expert Comment

by:leakim971
ID: 33808887
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
 
LVL 82

Expert Comment

by:leakim971
ID: 33808948
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
 
LVL 24

Author Comment

by:lenamtl
ID: 33808959
I'm confused...

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

0
 
LVL 24

Author Comment

by:lenamtl
ID: 33808973
oups ok you have posted the second part :)
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 82

Expert Comment

by:leakim971
ID: 33808998
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
 
LVL 82

Expert Comment

by:leakim971
ID: 33809003
>oups ok you have posted the second part :)

;-))
0
 
LVL 24

Author Comment

by:lenamtl
ID: 33809301
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
 
LVL 82

Expert Comment

by:leakim971
ID: 33809442
>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
 
LVL 24

Author Comment

by:lenamtl
ID: 33810195
I got this
 H¿al
for
Hôpital


0
 
LVL 82

Expert Comment

by:leakim971
ID: 33810309
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
 
LVL 24

Author Comment

by:lenamtl
ID: 33810468
same result

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33810902
could you confirm collation for the database table latin1_general_ci ? I was assuming the charset is latin1.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33811189
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
 
LVL 24

Author Comment

by:lenamtl
ID: 33814204
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
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33814341
>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
 
LVL 24

Author Comment

by:lenamtl
ID: 33814400
Ok fantastic it's work ok now!
Thanks you so much!
0
 
LVL 24

Author Closing Comment

by:lenamtl
ID: 33814403
Thanks for your patience!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33814404
You're very welcome! Thanks for the points! Have a nice week-end!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
date format angularjs2 16 40
listing all functions in JavaScript 19 103
Jquery Autocomplete PHP script 3 21
update field on focusout 15 22
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now