在MYSQL查询中没有返回撇号的字段

时间:2014-12-12 11:43:39

标签: php mysql

我有一个MSQL表,我在其中存储表单的结果。其中一列存储多选选项的结果,在输入数据之前使用序列化。

当我检索数据时,在while循环中,它完美地工作,除了2个条目,一个使用撇号'(条目是Contour d'Or),其他引用“(条目是Hair Extensions 18”)我似乎无法识别这些并将它们包含在查询中。

我已经尝试过mysqli_real_escape_string,但这也不起作用。我刚刚尝试了一些在我读到的另一个答案中建议的内容:  http://ben-major.co.uk/2012/12/mysql-searches-and-apostrophes/

感谢任何帮助:)

$q = "SELECT * 
      FROM Departments 
      WHERE `Department` = '$depart' AND `cookie` ='$value'";
$r = mysqli_query($connection, $q) or die("Error description: " . mysqli_error($connection));
$row = mysqli_fetch_assoc($r);

$Treatment = $row['Treatment'];
$Treatments = unserialize($Treatment);

foreach($Treatments as $key => $TreatmentN){
    echo $TreatmentN . " ";


    //INCOME 2014 & 2015
    $q = "SELECT (SUM(TurnOver)- SUM(Discount)) AS total 
          FROM Appointments 
          WHERE `Date` BETWEEN '2014-04-01' AND '2015-03-31' 
            AND `Treatment`LIKE '%$TreatmentN%' 
            OR REPLACE(`Treatment` , '\'', '' ) LIKE '%$TreatmentN%' 
            AND `cookie` ='$value'";
    $sum_query_resa  = mysqli_query($connection, $q);
    $rowa = mysqli_fetch_assoc($sum_query_resa);
    $income += $rowa['total'];
    echo $TreatmentN;
}

echo "<p>Total Income £" .sprintf('%0.2f', $income) ." ";

1 个答案:

答案 0 :(得分:1)

如果有人搜索到这个答案,我会重新构建数据库以搜索ID而不是名称。

应该从一开始就做到这一点,但我正在学习:)