1

i'm using ajax pagination method for search result. after setting mysql items to connect and setting utf8 for that, my result is'nt utf8 unicode,

my dabtabase data is utf8 and that correctly saved.but after fetch i cant get with correct unicode.

i dont have problem on localhost but after upload file on server i have problem

JQUERY :

$(document).ready(function(){
    $('#searchWordButton').click(function(){
        searchWord = $('#searchWord').val();
        if ( $.trim(searchWord) =='' ){
            alert('input is empty...');
            return false;
        } 
        else{
        $('[id^="hidden_div"]').hide();
            $('.div_search').show();                
            function loadData(page){
                $.ajax
                ({
                    type: "POST",
                    url: "load_data.php",
                    data: "page="+page+"&word="+searchWord,
                    success: function(msg)
                    {
                        $("#search_container").html(msg);
                    }
                });
            }
            loadData(1);  // For first time page load default results
            $('#search_container').on('click','.pagination li.active',function(){
                var page = $(this).attr('p');
                loadData(page);
            });                             
        }

    });

PHP load_data.php :

<?php
if($_POST['page'])
{
$page = $_POST['page'];
$word = $_POST['word'];
$cur_page = $page;
$page -= 1;
$per_page = 22;
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;

include 'config.inc';

$linkConnection = mysql_connect (LOCALHOST , USERNAME , DBpass);
mysql_query("set charset set utf8", $linkConnection);
mysql_query("set names 'utf8'", $linkConnection);           
mysql_select_db(DBname);

$query_pag_data = "SELECT id as msg_id ,subject as message , description from contents WHERE subject like '%$word%' LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());


$msg = "";
while ($row = mysql_fetch_array($result_pag_data)) {
    $subject     = htmlentities(htmlspecialchars_decode($row['message']));
    $description = htmlentities(htmlspecialchars_decode($row['description']));

    $msg .= "<div style='font-weight:bold;color:#063B27;'><a href='viewPage.php?topicID={$row['msg_id']}'>".$subject . "</a></div>";
    $msg .= "<div style='color:#378686;padding-right:30px;'>".mb_substr($description,0,200,'UTF-8').' ...' . "</div>";
}
$msg = "<div class='data'>" . $msg . "</div>"; // Content for Data

$query_pag_num = "SELECT COUNT(*) AS count FROM contents WHERE subject like '%$word%' ";
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);

if ($cur_page >= 7) {
    $start_loop = $cur_page - 3;
    if ($no_of_paginations > $cur_page + 3)
        $end_loop = $cur_page + 3;
    else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
        $start_loop = $no_of_paginations - 6;
        $end_loop = $no_of_paginations;
    } else {
        $end_loop = $no_of_paginations;
    }
} else {
    $start_loop = 1;
    if ($no_of_paginations > 7)
        $end_loop = 7;
    else
        $end_loop = $no_of_paginations;
}

$msg .= "<div class='pagination'><ul>";

// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
    $msg .= "<li p='1' class='active'>ابتدا</li>";
} else if ($first_btn) {
    $msg .= "<li p='1' class='inactive'>ابتدا</li>";
}

// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
    $pre = $cur_page - 1;
    $msg .= "<li p='$pre' class='active'>صفحه قبل</li>";
} else if ($previous_btn) {
    $msg .= "<li class='inactive'>صفحه قبل</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {

    if ($cur_page == $i)
        $msg .= "<li p='$i' style='color:#fff;background-color:#006699;' class='active'>{$i}</li>";
    else
        $msg .= "<li p='$i' class='active'>{$i}</li>";
}

// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
    $nex = $cur_page + 1;
    $msg .= "<li p='$nex' class='active'>صفحه بعد</li>";
} else if ($next_btn) {
    $msg .= "<li class='inactive'>صفحه بعد</li>";
}

// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
    $msg .= "<li p='$no_of_paginations' class='active'>انتها</li>";
} else if ($last_btn) {
    $msg .= "<li p='$no_of_paginations' class='inactive'>انتها</li>";
}
$total_string = "<span class='total' a='$no_of_paginations'>صفحه <b>" . $cur_page . "</b> از <b>$no_of_paginations</b></span>";
$msg = $msg . "</ul>"  . $total_string . "</div>";  // Content for pagination

echo $msg;
    }

RESULT :

ع�د سع�د �طر در ب�تاز�

ر�ز د�ش�ب� 30ش�ر��ر1388 �& ...

ح��� �ا� ش�ا� � ع�د سع�د �طر �بارک باد

«ا���� ص�� ع�� �ح��د �&Osla ...

1 Answer 1

1

Try adding this line after <?php

header('Content-Type: text/plain; charset=utf-8');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.