重複
の可能性: PHP エラー メッセージ「Notice: Use of undefined constant」はどういう意味ですか?
同じページに一度に 1 つの (レコード) 質問を表示しようとしています。コードの先頭に条件を追加して、ページの読み込みが初めてかどうかを確認し、そうであれば最初のレコードを表示します。それ以外の場合は、2 番目のレコードが表示される "else" ステートメントに移動します。レコードが表示されるたびに、カウンターが 1 つ増えます ($i++)。また、取得したすべてのレコードを配列に保存し、この配列から一度に 1 つずつレコードを読み取りました。ここで次のようなエラーが発生する理由がわかりません。
(1) 未定義の定数 i の使用 - 仮定 'i'
(2) 未定義インデックス: i
この問題を解決する方法を知っている人はいますか?
これが私のコードです:
<?php
$f_name = $_SESSION['first_name'];
$l_name = $_SESSION['last_name'];
$arr_rows;
$i;
if (!isset($_POST['next']))
{ //if form is not submitted,
$command2 = "SELECT user_id FROM user_info WHERE user_info.first_name = '$f_name'
and user_info.last_name = '$l_name'";
$command1 = "SELECT * FROM topics, documents WHERE topics.topic_id =documents.topic_id";
$i=0; // Counter for the number of documents per topic
$userid = mysql_query($command2);
$results = mysql_query($command1);
$num=mysql_numrows($results);
//////////////
$arr_rows = array();
while( $row = mysql_fetch_array( $results ) )
$arr_rows[] = $row;
$arr = mysql_fetch_row($userid);
$id_user = $arr[0];
echo $f_name;
$relevancy = "This is the first time to load this page";
$f1=$arr_rows[i]['topic_name'];
$f1_topic_description=$arr_rows[i]['topic_descrip'];
$f1_doc_content=$arr_rows[i]['doc_content'];
++$i;
}
else
{ //otherwise,
$relevancy = $_POST['RadioGroup1'];
$f1=$arr_rows[i]['topic_name'];
$f1_topic_description=$arr_rows[i]['topic_descrip'];
$f1_doc_content=$arr_rows[i]['doc_content'];
++$i;
}
?>