我有这行代码:
$query=$db->prepare("SELECT post_id, title, LEFT(body, 400), category FROM posts INNER JOIN categories ON categories.category_id=posts.category_id ORDER BY post_id DESC LIMIT $start, $per_page");
LEFT(body,400)
不会只查询 400 个字符,它会查询除最后一个单词之外的所有字符。这是我用来回显查询的代码(它在带有 db 的 while 循环中)
<p><?php
$body_sub = substr($body, 0). "...<a href='post.php?id=$post_id'> Continue Reading →</a>";
echo nl2br($body_sub);
?></p>