私は基本的に、クエリでループを実行し、PHP のバッファリングを使用してテンプレート ファイルをループに挿入しています。問題は、クエリに複数の結果がある場合、2 つ以上の同一の結果になることです (mysql 結果行の次のデータではなく、同じデータをループします)。
関数...
function get_blocks(){
$query = "SELECT * FROM `my_table`";
$results = mysql_query($query);
while($data = mysql_fetch_assoc($results){
extract($data, EXTR_SKIP);
ob_start();
include(dirname(__FILE__) . '/templates/infoBlock.php');
$returnString .= ob_get_clean();
}
echo $returnString;
}
テンプレートは次のようになります。
<div>
Hi my name is <?php echo $name; ?>
<br>
and my age is <?php echo $age; ?>
</div>
したがって、2 つのレコードがある場合:
record 1
name: Joe
age: 42
record 2
name: Sam
age: 35
私はで終わる
Hi my name is Joe
and my age is 42
Hi my name is Joe
and my age is 42
それ以外の
Hi my name is Joe
and my age is 42
Hi my name is Sam
and my age is 35
私はすでに試しました
echo ob_get_clean();
$returnString を関数から取り出して無駄に...
考え?