php mysql 查询后过滤

发布于 2024-10-31 16:20:30 字数 509 浏览 9 评论 0原文

尝试在查询后过滤结果。需要在tinytext字符串中找到一个字符串。看起来像:会计、ACT、代数 1、代数 2、美国历史、生物学、微积分、经济学、英语、欧洲历史、几何、语法、文学、钢琴、校对、心理学、阅读、SAT 数学、SAT 阅读、 SAT 写作、统计、小提琴、词汇、

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

$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++;
}

Trying to filter the results after a query. Need to find a string inside of a tinytext string. That looks like: 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,

Code - subject string to find is $subject and the list to search is $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++;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉溺在你眼里的海 2024-11-07 16:20:30

你的做法完全错误。

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

you are doing it completely the wrong way.

  1. Such a filtering should be done on the DB side, not in PHP.
  2. These subjects should not be stored like that but in separate fields in a relational table.
佞臣 2024-11-07 16:20:30

虽然我同意 Shrapnels 上校的回答,但在您的具体情况下,您正在寻找 strpos 函数(如果你确实想在 PHP 中执行此操作)

While I agree with Col. Shrapnels answer, in your specific case you are looking for the strpos function if you really want to do it in PHP

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文