PHP mysql过滤后查询


php mysql filter after query

尝试在查询后过滤结果。需要在一个tinytext字符串中找到一个字符串。看起来像:accounting, ACT, algebra 1, algebra 2, American history, biology, calculus, economics, English, European history, geometry, grammar, literature, piano, proofreading, psychology, reading, SAT math, SAT reading, SAT writing, statistics, violin, vocabulary,

代码 -要查找的主题字符串是$subject,要搜索的列表是$row['SubjectList']

$result = mysql_query($query, $dbConn);
$i=0;
while ($row = @mysql_fetch_assoc($result)){
    $results[$i]['Name'] = $row['Name'];
    $results[$i]['Zip'] = $row['ZipCode'];
    $results[$i]['SubjectList'] = $row['SubjectList'];
    $i++;
}

你完全错了。

    这样的过滤应该在DB端完成,而不是在PHP中。
  1. 这些主题不应该像那样存储,而应该存储在关系表中的单独字段中。

虽然我同意Col. Shrapnels的回答,但在您的具体情况下,如果您真的想在PHP中使用strpos函数