我正在開發一個web服務和android應用程序web服務是在PHP從MySQL數據庫獲取數據...我遇到的問題是,一些項目有多個細節,但我的代碼是隻爲每個項目提供一個細節。我以JSON格式獲取數據。嵌套的while循環不工作
您可以檢查此Here
這裏是我的代碼提前
function requiredData(){
$db = $this->dbConnection();
//$sql = "SELECT * FROM projects JOIN project_details ON projects.project_id=project_details.project_id";
$sql = "SELECT * FROM projects";
$queryResult = $db->query($sql);
if($queryResult->num_rows > 0){
while($row = $queryResult->fetch_assoc()){
$pid = $row['project_id'];
$detailsql = "SELECT * FROM project_details WHERE project_id=$pid";
$sqlResult = $db->query($detailsql);
if($sqlResult->num_rows > 0){
while ($d = $sqlResult->fetch_assoc()){
$r = array(
"project_id" => $d['project_id'],
"project_detail" => array(
"work_done" => $d['project_detail'],
"payment_for_work" => $d['project_payment'],
"payment_status" => $d['project_payment_status'],
"detail_id" => $d['project_detail_id']
)
);
}
}
$results[$row['project_name']] = array(
"project_id" => $row["project_id"],
"project_start_date" => $row["project_start_date"],
"project_due_date" => $row["project_due_date"],
"project_currency" => $row["project_currency"],
"project_work_details" => $r
);
}
}
return $results;
}
感謝您的幫助
什麼?我檢查了你指定的鏈接,它顯示了多個項目。你到底想要什麼? – Umair
一些項目有多個project_details ...但目前有一個顯示...例如項目ID 20有多個project_detail數組,,,但只有一個顯示出來... – FaISalBLiNK