我遇到了 MySQL LIKE 没有返回所有可能结果的问题。我有以下代码:
<?php
$query = "SELECT `user_id`,
`rank`,
`habbo_name`,
`rating`,
`branch`
FROM `personnel`
WHERE status='active' AND
rating='(DIROPS)'
ORDER BY `habbo_name`";
$result = $con->prepare($query);
$result->execute();
while ($row = $result->fetch())
{
echo "<b>DIROPS:</b> " . htmlspecialchars($row['habbo_name']) . "<br>";
}
$query = "SELECT `user_id`,
`rank`,
`habbo_name`,
`rating`,
`branch`
FROM `personnel`
WHERE status='active' AND
rating='(CO TECOM)' AND
`branch`='usmc'
ORDER BY `habbo_name`";
$result = $con->prepare($query);
$result->execute();
while ($row = $result->fetch())
{
echo "<b>CO TECOM:</b> " . htmlspecialchars($row['habbo_name']) . "<br>";
}
$query = "SELECT `user_id`,
`rank`,
`habbo_name`,
`rating`,
`branch`
FROM `personnel`
WHERE status='active' AND
rating='(XO TECOM)' AND
`branch`='usmc'
ORDER BY `habbo_name`";
$result = $con->prepare($query);
$result->execute();
while ($row = $result->fetch())
{
echo "<b>XO TECOM:</b> " . htmlspecialchars($row['habbo_name']) . "<br>";
}
?>
<br>
<?php
$query = "SELECT `user_id`,
`rank`,
`habbo_name`,
`rating`,
`branch`
FROM `personnel`
WHERE status='active' AND
`rating` LIKE '%(TECOM%' OR
`rating` LIKE '%/TECOM%' AND
status='active'
ORDER BY `habbo_name`";
$result = $con->prepare($query);
$result->execute();
while ($row = $result->fetch())
{
echo "<b>TECOM:</b> " . htmlspecialchars($row['habbo_name']) . "<br>";
}
?>
据我所知,这应该打印出评级设置为(DIROPS)、(CO TECOM)、(XO TECOM)然后是(TECOM 或 /TECOM)的人。
我遇到的问题是只有 DIROPS 和其他几个被退回。这是我从该代码中得到的结果:
谁能让我知道我哪里出错了?谢谢!
编辑:它应该显示的记录:-
TEO-emo12 (DIROPS) RockerManiac123 (CO TECOM) Rach-L (Lugn) (XO TECOM) Reyess (TECOM) zachary1142 (AuXHiDef-) (TECOM) norsk.no (TECOM) lordoftjefly (mingrana) (PPO/TECOM) spen1000 (TECOM/DI)