如何在mysql中获得单词不超过40个字符的列


How do you get columns in mysql that has no word greater than 40 characters?

基本上,我正在尝试在php中创建一个函数,该函数将为我提供最新的列(消息),该列的单词不超过40个字符。我能够获得最新的消息,但我不知道如何只获得单词不超过40个字符的最新消息。请参阅$callrecent变量。

<?php
function recentpost($postnum) {
$callrecent = "SELECT message FROM messages WHERE message (HAS NO WORD GREATER THAN 40 CHARACTERS) ORDER BY msg_id DESC LIMIT $postnum,1";
$callrecent_run = mysql_fetch_assoc(mysql_query($callrecent));
$message = stripslashes($callrecent_run['message']);
return $message;
}
?>

您可以使用正则表达式

SELECT message
FROM messages
WHERE message not regexp '[[:alnum:]]{41}'
ORDER BY msg_id DESC
LIMIT $postnum, 1

尝试

  SELECT message
    FROM messages
   WHERE LENGTH(message) <= 40
ORDER BY msg_id DESC
   LIMIT $postnum, 1