顯示「Undefined variable:display1」。 我能夠顯示while循環。 問題是$ display1已經在while循環中定義了,它必須在它中,因爲$ i增量。我想使用循環中的變量,但while循環中定義的變量
//SQL for display category name
$query1="SELECT cat_name FROM restaurant_category WHERE rest_id={$display}";
$result1=mysql_query($query1);
$rowNum1=mysql_num_rows($result1);
//SQL for display dish information of each category
$query3="SELECT cat_id FROM restaurant_category WHERE cat_name={$display1}";
$result3=mysql_query($query3);
$display3=mysql_query($result3);
$query2="SELECT dish_name, dish_description, dish_price FROM dish WHERE cat_id={$display3}";
$result2=mysql_query($query2);
$rowNum2=mysql_num_rows($result2);
$data=mysql_fetch_row($result2);
while($i<$rowNum1)
{
$display1=mysql_result($result1,$i,"cat_name");
//display category name
while($j<$rowNum2)
{//display dish information}
}
http://www.php.net/manual/en/language.variables.scope.php –
PHP是不會時間旅行爲你並執行while循環來獲取結果之前,你已經實際上運行查詢產生的結果在第一位。 –