Solved

Character endoding after reading from db

Posted on 2009-03-30
3
269 Views
Last Modified: 2013-11-19
the snippet bellow, it retrieves some data from the db and renders it, it works find except that the rendered text in line echo "$um[jr_comment]"; is displayed like ??? ?????? ????? (question marks) when the letters are non-latin (they are Arabic letters) , is there a way to avoid that?

the rest of the page is displaying correctly because it is done thru joomla, that portion is the only non-standard part of the page that reads directly from the db.
$ans=mysql_query("SELECT * FROM `jr_review_fields`WHERE reviewid in (	$alist)");
	//$um=mysql_num_rows($ans);
	//if($um!='0')
	while($um=mysql_fetch_array($ans)) 
		{
		$us=mysql_query("SELECT username FROM `jr_comments`WHERE `id` = '$um[revid]'");
		while($av=mysql_fetch_array($us))
			{
			echo '<b>'.$av[username].':</b>';
			echo "$um[jr_comment]";
			echo "<br>";
		}
		}

Open in new window

0
Comment
Question by:TheSilverBullet
3 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 24017138
try execute this statement before your Select SQL statement:

$result = mysql_query('SET NAMES utf8;');

//...

$ans=mysql_query("SELECT * FROM `jr_review_fields`WHERE reviewid in (   $alist)");

//...


you may also change the meta setting to be like this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


hope this helps

0
 
LVL 3

Expert Comment

by:dr_lionheart
ID: 24017373
try to put this code at the begining of this php file
header("Content-type: text/html; charset=windows-1256");

Open in new window

0
 

Author Closing Comment

by:TheSilverBullet
ID: 31564219
Bravo!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 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