从mysqli查询结果中删除不需要的代码

时间:2014-07-04 05:20:54

标签: php mysqli

请帮忙。

我试图查询mysqli数据库,使用php在我的主页上显示我的部分博客文章。它输出一个杂乱的字符,如链接所示。 www.myimcm.com(不需要的逗号和类似的东西。简单的代码是:

 $q ="SELECT SUBSTRING_INDEX(post_content,' ',130) AS post,(post_title) AS title,ID AS id FROM wp_posts WHERE post_type='post' ORDER BY post_date DESC LIMIT 1";
$r = @mysqli_query ($dbc, $q); // Run the query.

if ($r) { // If it ran OK, display the records.
    echo '<h2>LATEST FROM OUR GUIDES</h2>'; 
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
     echo"<p class='title'>". ($row['title'])."</p>";
     echo nl2br($row['post']);

echo '<a href="http://guides.myimcm.com/wp"> Continue reading</a>';

}
    mysqli_free_result ($r); // Free up the resources.  

} else { // If it did not run OK.

    // Public message:
    echo '<p class="error">The are no latest from our blog. We apologize for any inconvenience.</p>';

    // Debugging message:
    echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';

} // End of if ($r) IF.
mysqli_close($dbc); // Close the database connection.

2 个答案:

答案 0 :(得分:0)

在您的网页中使用utf-8编码。 在头部使用此代码。

 header("Content-Type: text/html; charset=utf-8");

答案 1 :(得分:0)

您的网页声称以UTF-8编码,但事实并非如此。它包含以下八位字节:859192a0(单独使用)无效UTF-8。 它们可能来自一个Windows-125x字符编码,例如Windows-1252

您需要设置数据库,以便为数据库,表和连接使用正确的字符编码。有关详细信息,请参阅MySQL manualPHP manual

相关问题