如何从数据库导出值并回显由< hr />分隔的所有值,除了第一个和最后一个结果?

How can I export values from a database and echo all it separated by an <hr />, except the first and the last results??

$stmt = $db->prepare("SELECT `title`, `content` FROM `news` ORDER BY title ASC");
$stmt->execute(array($category));
foreach($stmt as $row){
    echo "<p>" . $row['title'];
    echo $row['content'] . "</p> <hr />";
}

it outputs:

<p>title1
content1</p>
<hr>
<p>blabla
blabla</p>

<!--My question is how to remove this hr-->
<hr>

I tried to use a for cicle, but it didn't work.

thanks in advance

You could try something like this:

$stmt = $db->prepare("SELECT `title`, `content` FROM `news` ORDER BY title ASC");
$stmt->execute(array($category));

$numResults = $stmt->rowCount();
$counter = 0;
foreach($stmt as $row){
  echo "<p>" . $row['title'];

if (++$counter == $numResults) {
        // last row
        echo $row['content'] . "</p>";
    } else {
        // not last row
        echo $row['content'] . "</p> <hr />";
    }
}

That will count the rows up till the last one, and skip writing the HR for that one.