Why does the result of my query to the database show in some letters? [duplicate]

0

I want to show some concrete data of my database in a widget of my wordpress by means of a php function and a query to a MySQL database, but the problem that I am having is that it is shown in the letters with accent. My HTML has this formatted in UTF-8 and my database as well. This is my php function:

 function show_venda(){
        $sql = "SELECT * FROM wp_posts WHERE post_type = 'listing' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 6";
        $query = mysqli_query($conexion, $sql);
        $html_code = '<section class="widget featured-listings">';
        while ($data = mysqli_fetch_array($query)) {
            $id = $data['ID'];
            $sql_sentence = "SELECT * FROM wp_postmeta WHERE post_id = '$id' AND meta_key LIKE '_listing%'";
            $qry = mysqli_query($conexion, $sql_sentence);
            while ($result = mysqli_fetch_array($qry)) {
                if ($result['meta_key'] == '_listing_text') {
                    $text = $result['meta_value'];
                }elseif ($result['meta_key'] == '_listing_price') {
                    $price = $result['meta_value'];
                }elseif ($result['meta_key'] == '_listing_address') {
                    $address = $result['meta_value'];
                }elseif ($result['meta_key'] == '_listing_city') {
                    $city = $result['meta_value'];
                }
            }
            $html_code .= '
            <div class="listing entry">
              <div class="widget-wrap">
                <div class="listing-wrap">
                  <span class="listing-price">'.$price.' €</span>
                  <span class="listing-text">'.$text.'</span>
                  <span class="listing-address">'.$address.'</span>
                  <span class="listing-city-state-zip">'.$city.'</span>
                </div>
              </div>
            </div>';
        }
        $html_code .= '</section>';
        return $html_code;
    }
    add_shortcode('show_venda', 'show_venda');
    
asked by Hamza Saddouki 15.06.2017 в 17:42
source

1 answer

0

Do you have the meta utf in your HTML?

That may be the reason, here the tag in case you did not have it:

<meta charset="utf-8"> 

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

The results are the same with any of the two tags

If you have any questions, comment.

Luck.

    
answered by 15.06.2017 в 17:45