3 Replies - 7450 Views - Last Post: 20 April 2010 - 03:35 AM Rate Topic: -----

#1 blakpower  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 26
  • Joined: 09-February 09

PHP & MySQL - Displaying Arabic text from DB on to page

Posted 19 April 2010 - 09:31 AM

Hi

I am having an issue displaying arabic text that is stored in the DB on to the php page. the MySQL table is using Charset utf8 and Collation utf8_general_ci. In the DB is displays properly when i try retrieving it useing the following. it doesnt work.

this is the code i am using:

$conn=mysql_connect(HOSTNAME,USERNAME,PASSWORD) or die(mysql_error());
	
	mysql_query("SET NAMES 'utf8'", $conn);
	
	/* select default database*/
	mysql_select_db(DATABASE);
	
	
	$sql = "SELECT distinct(SUBSTRING_INDEX(`destination`, '-',1)) as 'country' from `ar` order by destination ASC ";

	$result=mysql_query($sql);
	?>
	        </p>
			<form id="form1" name="form1" method="post" action="">
		      <span style=" font-weight:bold; color:#00adef; font-size:14px;">اختر البلد</span>
		      <select name="country" id="country">
		      <option value="0" selected="selected">اختر</option>
		      <?php while($rows=mysql_fetch_assoc($result)){?>
		        <option value="<?php echo base64_encode($rows['country']) ?>"><?php echo utf8_encode($rows['country']) ?></option>
			 <?php }
			  mysql_free_result($result);?>
		      </select>
		    </form>


the current output I am getting is: أذربŠجا

can anyone please advise on what to do.

Is This A Good Question/Topic? 0
  • +

Replies To: PHP & MySQL - Displaying Arabic text from DB on to page

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: PHP & MySQL - Displaying Arabic text from DB on to page

Posted 19 April 2010 - 11:17 AM

Looks like it might be the browser or HTML page's encoding/charset. Make sure they're set to UTF-8
Was This Post Helpful? 0
  • +
  • -

#3 blakpower  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 26
  • Joined: 09-February 09

Re: PHP & MySQL - Displaying Arabic text from DB on to page

Posted 20 April 2010 - 01:07 AM

View PostJackOfAllTrades, on 19 April 2010 - 10:17 AM, said:

Looks like it might be the browser or HTML page's encoding/charset. Make sure they're set to UTF-8


the page is set to utf-8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


There is other arabic text on the page that displays properly.
Was This Post Helpful? 0
  • +
  • -

#4 blakpower  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 26
  • Joined: 09-February 09

Re: PHP & MySQL - Displaying Arabic text from DB on to page

Posted 20 April 2010 - 03:35 AM

I fixed the issue
the problem was with
<option value="<?php echo base64_encode($rows['country']) ?>"><?php echo utf8_encode($rows['country']) ?></option>



removing the echo utf8_encode from $rows['country'] allowed it to be displayed properly
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1