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

时间:2016-01-24 11:03:38

标签: php mysql

我是MySQL的PHP​​局外人。

我的以下代码正在测试:http://www.findoutbusiness.com/company/index.php?crno=1

如何为以下问题编写php代码:

  • 如何按顺序编写代码可以支持utf-8 /中文?因为现在中国公司正在展示" ?????"只要。 phpMyAdmin - 数据库可以支持中文。只有index.php不能支持中文。

  • 如何编写用于计算日期的代码?

  • 如果活动状态为"解散",则计算"解散日期 - 合并日期"

  • 如果活动状态为" Live",则计算"今天 - 公司成立日期"

我想表明公司正在运行多少:?年 ?几个月?天。

非常感谢你的帮助和帮助。支持!



<?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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我是中国人,对于您的问题,您可以在创建连接后添加以下代码。

Private Sub CommandButton1_Click()

Dim rng As Range
Dim cell As Range
Set rng = Range("D5:F35,D43:F73,J5:L35,J43:L73,P5:R35,P43:R73,V5:X35,V43:X73,AB5:AD35,AB43:AD73,AH5:AJ35,AH43:AJ73")

For Each cell In rng
    If cell.Value Like "*A*" Or cell.Value Like "*B*" Or cell.Value Like "*C*" Or cell.Value Like "*D*" Or cell.Value Like "*F*" Then
        cell.NumberFormat = ";;;"
    End If
Next cell

End Sub



Sub Macro1()

If cell.NumberFormat = ";;;" Then
    cell.NumberFormat = "General"
End If

End Sub

希望这可以帮到你。