我想問一下如何顯示多個row
的數據而不是隻有一個row
。下面的代碼將只顯示一行記錄,而不是多個記錄可用。我在這裏使用mysqli_prepare
陳述。或者問題出在我的android studio編碼上?我的應用程序使用登錄功能和編碼如下所示。php腳本只顯示一行數據而不是很多在android工作室
<?php
$host="DB_HOST";
$user="DB_USER";
$password="DB_PASSWORD";
$db="DB_NAME";
$con = mysqli_connect($host,$user,$password,$db);
$parentic=$_POST["ParentIC"];
$password=$_POST["Password"];
$selectquery = mysqli_prepare($con, "SELECT Parents_Data.Name, Student_List.StudName, Student_List.StudIC, Student_List.Form,Student_List.Class,discipline_record.Date,discipline_record.RulesCode, discipline_record.TypesofMistakes,discipline_record.Punishment FROM discipline_record LEFT JOIN Student_List ON discipline_record.StudIC = Student_List.StudIC LEFT JOIN Parents_Data ON Student_List.ParentIC = Parents_Data.ParentIC WHERE Parents_Data.ParentIC = ? AND Parents_Data.Password = ? ");
mysqli_stmt_bind_param ($selectquery, "ss", $parentic, $password);
mysqli_stmt_execute($selectquery);
mysqli_stmt_store_result($selectquery);
mysqli_stmt_bind_result($selectquery,$name,$studname,$studic,$form,$classs,$ddate,$code,$mistakes,$punishment);
$user = array();
while(mysqli_stmt_fetch($selectquery))
{
$user[name]=$name;
$user[studname]=$studname;
$user[studic] = $studic;
$user[form]=$form;
$user[classs]=$classs;
$user[ddate]=$ddate;
$user[code]=$code;
$user[mistakes]=$mistakes;
$user[punishment]=$punishment;
}
echo json_encode($user);
mysqli_stmt_close($selectquery);
mysqli_close($con);
?>
使用'foreach'循環,然後再試一次。 –
@ChoncholMahmud你能指導我嗎?因爲我是新手。謝謝 –
在while循環內移動你的echo json_encode – RST