Home  >  Article  >  php教程  >  PHP连接数据库,查询结果在页面显示乱码的解决方法

PHP连接数据库,查询结果在页面显示乱码的解决方法

PHP中文网
PHP中文网Original
2016-05-25 16:58:10988browse

跳至

<?php
	header("Content-type:text/html;charset=utf-8"); 
    $mysql_server_name="localhost"; //数据库服务器名称
    $mysql_username="root"; // 连接数据库用户名
    $mysql_password="123456"; // 连接数据库密码
    $mysql_database="td_oa"; // 数据库的名字
    
    // 连接到数据库
    $conn=mysql_connect($mysql_server_name, $mysql_username,
                        $mysql_password);
	//解决乱码 
	mysql_query("SET NAMES &#39;UTF8&#39;"); 
	mysql_query("SET CHARACTER SET UTF8"); 
    mysql_query("SET CHARACTER_SET_RESULTS=UTF8&#39;"); 	
                        
     // 从表中提取信息的sql语句
   // $strsql="SELECT * FROM `crm_order`";
	$strsql="select a.field4 as &#39;车号&#39;,a.field8 as&#39;任务号&#39;,a.field5 as&#39;装货日期&#39; ,a.field6 as&#39;供应商名称&#39;,a.field7 as&#39;采购价格&#39; from `crm_storage` a left join `crm_order` b 
    on a.field4=b.field2 and a.field8=b.field16
	where (b.field8=0 or b.field8 is null)
	and DATE_ADD(a.field5,INTERVAL 4 day)<CURDATE()";
	
	
    // 执行sql查询
    $result=mysql_db_query($mysql_database, $strsql, $conn);
    // 获取查询结果
    $row=mysql_fetch_row($result);
    
    //echo "";
    echo "";
    echo &#39;&#39;;
    echo &#39;&#39;;

    // 显示字段名称
    echo "";
    for ($i=0; $i<mysql_num_fields($result); $i++)
    {
      echo &#39;&#39;.
      mysql_field_name($result, $i);
      echo "";
    }
    echo "";
    // 定位到第一条记录
    mysql_data_seek($result, 0);
    // 循环取出记录
    while ($row=mysql_fetch_row($result))
    {
      echo "";
      for ($i=0; $i

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php 多文件上传Next article:PHP最基本上传代码示例