You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PHP的MySQL查询中排除含指定短语的描述结果?

Solution to Exclude Entries with Specific Phrases in Description

Hey there! I see you want to filter out any project entries where the description contains "cheap" or "lowest price". Let's adjust your SQL query to add that exclusion logic.

Modified Query Explanation

We'll add NOT LIKE conditions to your WHERE clause, using SQL wildcard % to match any text before or after the target phrases. This ensures we exclude any row where the description includes those phrases anywhere in the text.

Updated PHP Code

<?php 
$query = "SELECT * FROM project_data 
          WHERE budget='200' 
            AND description NOT LIKE '%cheap%' 
            AND description NOT LIKE '%lowest price%' 
          ORDER BY id DESC LIMIT 0, 100"; 
$database->setQuery( $query ); 
$rows = $database->loadObjectList(); 
?>

<?php foreach( $rows as $row ){?> 
    <?=$row->budget?> <?=$row->title?> <?=$row->description?> 
<?php }?>

Extra Tip for Case Insensitivity

If you need to exclude variations like "Cheap", "CHEAP", or "Lowest Price" (different capitalization), you can make the check case-insensitive. For MySQL, use the LOWER() function to standardize the text before checking:

AND LOWER(description) NOT LIKE '%cheap%' 
AND LOWER(description) NOT LIKE '%lowest price%'

This converts the description to lowercase first, so any case variation of the target phrases will be excluded.

内容的提问来源于stack exchange,提问作者mwz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:54:38