dongyan5641 2016-01-24 11:03
浏览 71

如何用MySQL编写php代码用于utf-8(显示中文),计算天数

I'm an outsider for the php with MySQL.

For my below code is testing : http://www.findoutbusiness.com/company/index.php?crno=1

How to write php code for the below questions:

  • How to write a code in order can support utf-8 / Chinese? Because now the Chinese company is showing "?????" only. The phpMyAdmin - database is can support Chinese. ONLY the index.php cannot support Chinese.

  • How to write a code for calculating the days ?

  • If the Active Status is "Dissolved", then calculate "Date of Dissolution - Date of Incorporation"

  • If the Active Status is "Live", then calculate "today - Date of Incorporation"

I want to show the company is running how many: ? year ? months ? days.

Thank you very much for your help & support !

<?php

$servername = "localhost";
$username = "abc";
$password = "abc1234";
$dbname = "company";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 



// select data

$sql    = 'SELECT * FROM ComData WHERE com_no = '. $_GET['crno'];
$result = $conn->query($sql);



if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $pageTitle = $row['com_eng_name'] . $row['com_chi_name'];

        $com_no = $row['com_no'];           
        $com_eng_name = $row['com_eng_name'];
        $com_chi_name = $row['com_chi_name'];       
        $com_type = $row['com_type'];   
        $date_of_incorp = $row['date_of_incorp'];   
        $active_status = $row['active_status']; 
        $date_of_dissolution = $row['date_of_dissolution'];         
        $remarks = $row['remarks'];
    

    }
} else {
    echo "No Results";
}

$conn->close();
?>

<!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>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta name="rights" content="www.findoutbusiness.com" />
  <title><?php echo $pageTitle; ?> - Hong Kong Company Information</title>
</head>

<body >
<h2 >Hong Kong Company Information</h2>

<form action="http://www.findoutbusiness.com/company/index.php" id="cse-search-box">
    <input type="text" name="crno" size="10" />
    <input type="submit"  value="Company Code Search" />
</form>  
<br>



<table border="1" cellspacing="1" cellpadding="1">
  <tr>
    <td><strong>CR No.:<br>公司編號:</strong></td>
    <td><?php echo $com_no; ?></td>
  </tr>
  <tr>
    <td><strong>Company Name:<br>公司名稱:</strong></td>
    <td><?php echo $com_eng_name; ?> <?php echo $com_chi_name; ?> </td>
  </tr>
  <tr>
    <td><strong>Company Type:<br>公司類別:</strong></td>
    <td><?php echo $com_type; ?></td>
  </tr>
  <tr>
    <td><strong>Date of Incorporation:<br>成立日期:<br></strong></td>
    <td><?php echo $date_of_incorp; ?></td>
  </tr>
  <tr>
    <td><strong>Active Status:<br>公司現況:</strong></td>
    <td><?php echo $active_status; ?></td>
  </tr>
  <tr>
    <td><strong>Date of Dissolution:<br>已告解散日期:</strong></td>
    <td><?php echo $date_of_dissolution; ?></td>
  </tr>
  <tr>
    <td><strong>Remarks:</strong></td>
    <td><?php echo $remarks; ?></td>
  </tr>
</table>

<br><br>
The company <?php echo $days; ?> days
<br>
<b>
<a href="index.php?crno=<?php echo ($_GET['crno'] - 1); ?>" >Previous Company</a> | 
<a href="index.php?crno=<?php echo ($_GET['crno'] + 1); ?>" >Next Company</a>
</b>

<br><br>

<form action="http://www.findoutbusiness.com/company/index.php" id="cse-search-box">
    <input type="text" name="crno" size="10" />
    <input type="submit"  value="Company Code Search" />
</form>  


</body>
</html>

</div>
  • 写回答

1条回答 默认 最新

  • dongzai0020 2016-01-24 12:16
    关注

    I'm a Chinese, for your question, you can add the following codes after creating connection.

    if(!$conn->set_charset("utf-8")){
       exit("Error loading character set utf8".$conn->error);}
    

    Hoping this can help you.

    评论

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决