私は、私はDBに保存されているヘッドラインをプルしようとしている、彼らはすべて一意のIDを持って..私はそれらを呼び出すことができるようにする方法が必要です。問題Withステートメント
$stmt = $con->prepare("SELECT * FROM news WHERE type = 'sports'");
$stmt->execute();
while($rfr=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="row">
<div class="col-lg-4">
<img src="<?php echo $rfr['folder'] . $rfr1['file'];?>.jpg" >
<h2><?php echo $rfr['headline'];?></h2>
<p>V.A. conducts study to determine effectiveness</p>
<p><a class="btn btn-primary" href="#" role="button">Read More »</a></p>
</div>
<div class="col-lg-4">
<img src="imgs/news/n4.jpg">
<h2><?php echo $rfr['headline'];?></h2>
<p>The Rev. Daniel Berrigan, a Roman Catholic priest and peace activist who was imprisoned for burning draft files in a protest against the Vietnam War, died Saturday. He was 94.</p>
<p><a class="btn btn-primary" href="#" role="button">Read More »</a></p>
</div>
<div class="col-lg-4">
<img src="imgs/news/n1.jpg">
<h2><?php echo $rfr['headline'];?></h2>
<p>President Barack Obama is getting one more chance to poke fun at fellow politicians, the press and himself at the annual White House Correspondents' Dinner.</p>
<p><a class="btn btn-primary" href="#" role="button">Read More »</a></p>
</div>
<?php
}
?>
毎回このコードを実行します。毎回ID1の見出しのみを入力します。それは..私はそれがそのタイプのすべての見出しを選択したい重複ポストのトン..
を作るthatsの理由なぜあなただけのforeachを使用していないWHILE()
'' type'がwhile'は 'sports'あるすべてのレコードをループします。 DBレベルで実行しても同じ結果は得られませんか?たぶんあなたは 'distinct 'か' group by'を探しているかもしれません.. – chris85
ちょっとしたメモとして、 '<?php while(..):?>'( '{'の代わりに ' – Atticus