我有一個數據庫表有兩列,一列是ID,另一列是顏色。想象一下,我有3條線路在此表中數據如下:使用MySQL在字符串中查找確切的文本
ID: 1 => Colors: Blue; Yellow; Red;
ID: 2 => Colors: Green; GreenYellow; Yellowgreen; Blue;
ID: 3 => Colors: Yellow; Blue;
如果我想打一個SQL調用知道是否有與黃色(黃剛,無綠黃或黃綠)寄存器。我該怎麼做? I'm,試圖:
$statement = $conexion->prepare("SELECT * FROM comentarios WHERE suscritos LIKE :suscritos");
$statement->execute(array(":suscritos" => "%Yellow%"));
$todos_mis_mensajes = $statement->fetchAll();
ID的結果:1,2和3
$statement = $conexion->prepare("SELECT * FROM comentarios WHERE suscritos LIKE :suscritos");
$statement->execute(array(":suscritos" => "%Yellow_"));
$todos_mis_mensajes = $statement->fetchAll();
ID的結果:沒有結果
$statement = $conexion->prepare("SELECT * FROM comentarios WHERE suscritos LIKE :suscritos");
$statement->execute(array(":suscritos" => "_Yellow%"));
$todos_mis_mensajes = $statement->fetchAll();
ID r esults:3
'(LIKE suscritos '黃色;%' OR suscritos LIKE '%黃色;%')' – BenM
工作!創建一個響應,以便我可以驗證。謝謝! –