显示数据库中的特殊字符

时间:2018-04-16 02:51:54

标签: javascript php jquery

例如,我想显示 Tan& Tan Developments

来自我的数据库。但是,我不知道为什么它总是只显示 Tan

我的代码如下所示

<?php
require_once 'dbconfig.php';

$developer = $_POST['developer']; //I get the developer name 

//this query is the get all the developer id 
$DevQuery="SELECT id AS `ID` FROM pams_developer WHERE developer_name=:name";
$dev_id = ($GetReport->GetID($DevQuery,$developer));//implode out the id from array 

$TotalSPAUnitQuery = "SELECT count(unit_id) AS 'COUNT' FROM pams_unit
JOIN pams_phase ON `pams_unit`.`phase_id`=`pams_phase`.`phase_id` AND `pams_unit`.`status_id`='3' AND `pams_unit`.`progress_id`='6'
JOIN pams_project ON `pams_project`.`project_id`=`pams_phase`.`project_id` 
JOIN pams_developer ON `pams_developer`.`id`=:dev_id AND  `pams_project`.`dev_id`=`pams_developer`.`id`";
$TotalSPAUnit = $GetReport->GetCount($TotalSPAUnitQuery,$dev_id);

$TotalSPAGDVQuery = "SELECT FORMAT(SUM(sold_price),2) AS 'COUNT' FROM pams_unit
JOIN pams_phase ON `pams_unit`.`phase_id`=`pams_phase`.`phase_id` AND `pams_unit`.`status_id`='3' AND `pams_unit`.`progress_id`='6'
JOIN pams_project ON `pams_project`.`project_id`=`pams_phase`.`project_id` 
JOIN pams_developer ON `pams_developer`.`id`=:dev_id AND  `pams_project`.`dev_id`=`pams_developer`.`id`";
$TotalSPAGDV = $GetReport->GetCount($TotalSPAGDVQuery,$dev_id);


?>

<div class="well">
  <div class="reportTitle">Developer : <b><?php echo "$developer"; ?></b></div>
  <div class="reportTitle">Total SPA Unit : <b><?php echo "$TotalSPAUnit"; ?></b></div>
  <div class="reportTitle">Total SPA GDV : RM <b><?php echo "$TotalSPAGDV "; ?></b></div>
</div>

发送数据的表单:

    $('#submit').click(function(){
         var ajaxRequest; 
         ajaxRequest = new XMLHttpRequest();

         // this #developerSelect will get the value of the select option
         var developer = $('#developerSelect').val(); 

         console.log(developer); // this developer show "Tan & Tan Development in the log, worked fine "

        var queryString = "developer=" + developer;
        //this ajax-SPAGDVTotal.php is the php code that I show above
        ajaxRequest.open("POST", "ajax-SPAGDVTotal.php", true);
        ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajaxRequest.onreadystatechange = function(){
          if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('AJAX_SPAResult');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
          }
        }

        ajaxRequest.send(queryString); 

Image

$ developer只能显示 Tan ,但不能显示全名 Tan&amp; Tan Developments
任何人都可以帮我解决问题吗?

1 个答案:

答案 0 :(得分:0)

如果您想显示特殊字符,也许可以试试这个:

<?php echo htmlspecialchars($developer, ENT_QUOTES, 'UTF-8'); ?>