PDA

View Full Version : عدم نمایش اطلاعات به فارسی از دیتابیس



hamidhassas
دوشنبه 05 خرداد 1393, 23:58 عصر
من اطلاعات رو از دیتابیس میخونم ولی بجای فارسی ؟؟؟؟؟؟؟؟؟؟؟ نشون میده در صورتی که UTF-8 رو هم در صفحه قرار دادم

<!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>
<title>Multiple drop down list box from plus2net</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<script language="JavaScript" type="text/javascript">
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='index.php?cat=' + val ;
}
</script>
<body>
<?php
$dbo = new PDO('mysql:host=localhost;dbname='.$general_databa se, $username, $password);
@$cat=$_GET['cat']; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not.
echo "Data Error";
exit;
}///////// Getting the data from Mysql table for first list box//////////
$quer2="SELECT DISTINCT `title`,`id` FROM `costs_group` order by `title`";
///////////// End of query for first list box////////////
/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
if(isset($cat) and strlen($cat) > 0)
{
$quer="SELECT DISTINCT `title` FROM `costs_group_type` where `costs_group_id`=$cat order by `title`";
}
else
{
$quer="SELECT DISTINCT `title` FROM `costs_group_type` order by `title`";
}
?>
<form method="post" name="f1" action="dd-check.php">
<select name="cat" onchange="reload(this.form)"><option value="">Select one</option>
<?php
foreach ($dbo->query($quer2) as $noticia2)
{
if($noticia2['id']==@$cat)
{
echo "<option selected value='$noticia2[id]'>$noticia2[title]</option>"."<BR>";
}
else
{
echo "<option value='$noticia2[id]'>$noticia2[title]</option>";
}
}
?>
</select>
<select name='subcat'><option value=''>Select one</option>
<?php
foreach ($dbo->query($quer) as $noticia)
{
echo "<option value='$noticia[title]'>$noticia[title]</option>";
}
?>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>


چطوری میتونم اتصال به دیتابیس رو از حالت زیر به صورت زیر در بیارم که شرط foreach هم اجرا بشه
از

$dbo = new PDO('mysql:host=localhost;dbname='.$general_databa se, $username, $password);

به


function general_connection($username,$password,$general_da tabase){
$general_con=mysql_connect($local,$username,$passw ord);
$db_select_general=mysql_select_db($general_databa se,$general_con);}

Mohammadsgh
سه شنبه 06 خرداد 1393, 01:06 صبح
اگه از pdo استفاده میکنید از این روش برای پارسی کردن استفاده کنید:لبخندساده:

$dsn = 'mysql:host=localhost;dbname=testdb';
$username = 'username';
$password = 'password';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);

$dbh = new PDO($dsn, $username, $password, $options);

hamidhassas
سه شنبه 06 خرداد 1393, 09:07 صبح
ممنون
چطوری میتونم اتصال به دیتابیس رو از حالت زیر به صورت زیر در بیارم که شرط foreach هم اجرا بشه
از

$dbo = new PDO('mysql:host=localhost;dbname='.$general_databa se, $username, $password);

به


function general_connection($username,$password,$general_da tabase){
$general_con=mysql_connect($local,$username,$passw ord);
$db_select_general=mysql_select_db($general_databa se,$general_con);}

119549