0

私は次のようなウェブサイト構造を持っています

<div id="title">
<h1> //call $title here after executing loop </h1>
</div>
<?php 
   ...
     while ($row = $result->fetch_assoc()) { $title = $row['title']; ?>

<h2> this is the <?php echo $title;?> </h2>
<?php } ?>

$titlewhileループステートメントの上にあるhtml要素の変数を引き続き使用または呼び出す方法はありますか?

whileループの上で呼び出すたびに、次のようなエラーが発生しますUndefined variable: id..

編集: 代わりに id を 'title' に変更

4

2 に答える 2

0

1 行だけを取得する場合は、ループは必要ありません。

<?php
$row = $result->fetch_assoc();
$title = $row['title'];
?>

<div id="title">
    <h1><?php echo $title; ?></h1>
</div>
于 2013-10-17T15:18:51.210 に答える