2016-04-09 13 views
-1

3 tablodan veri alıyorum: table.service_master_new, table.department_master ve table.document_master.json'da döngü yanıtı nasıl oluşturulur?

Tablo yapısını:

Structure of Service Master

Structure of Department master

tabloda

Structure of Document Master

veri:

Data of service table

data of department table

data of document table

ve veriler alınırken benim php kodu:

<?php 
include 'mysql.php'; 
$matrix = array(); 
$getServices = mysqli_query($db,"SELECT * FROM service_master_new"); 
while($row=mysqli_fetch_array($getServices,MYSQLI_ASSOC)){ 
    $xmatrix = array(); 
    $dept_code = $row['dept_code']; 
      $getDeptName = mysqli_query($db,"SELECT * FROM department_master WHERE Dept_Code='$dept_code'"); 
      while($row1 = mysqli_fetch_array($getDeptName,MYSQLI_ASSOC)){ 
       $xxmatrix = array(); 
       $dept_name = $row1['Dept_Name']; 
       $xmatrix['dept_name'] = $dept_name; 
       array_push($xmatrix, $dept_name); 

       $service_name = $row['service_name']; 
       $xmatrix['service_name'] = $service_name; 
       array_push($xmatrix, $service_name); 
       $contact_point = $row['contact_point']; 
       $xmatrix['contact_point'] = $contact_point; 
       array_push($xmatrix, $contact_point); 
       $timeline = $row['timeline']; 
       $xmatrix['timeline'] = $timeline; 
       array_push($xmatrix, $timeline); 

       $doc_codes = $row['doc_codes']; 
       $xdocs = array(); 
       $codes = explode(",",$doc_codes); 
       $countCodes = count($codes); 
       for($i=0;$i<$countCodes;$i++){ 
        $getDocs = mysqli_query($db,"SELECT * FROM document_master WHERE Doc_Code='$codes[$i]'"); 
        while($row4 = mysqli_fetch_array($getDocs,MYSQLI_ASSOC)){ 
         $doc_name = $row4['Doc_Name']; 
         array_push($xdocs, $doc_name); 
        } 
        $xmatrix['docs'] = $xdocs; 
       } 
     } 


    array_push($matrix, $xmatrix); 
} 
echo json_encode($matrix); 
?> 

ve bu alıyorum yanıttır:

[ 
{ 
0: "Fire", 
1: "No Objection Certificate", 
2: "O/O Chief Fire Officer", 
3: "15", 
dept_name: "Fire", 
service_name: "No Objection Certificate", 
contact_point: "O/O Chief Fire Officer", 
timeline: "15", 
docs: [ 
"Record of Rights Form 'F'", 
"Sketch Map", 
"Approved Building Plan", 
"Statutory License to carry business", 
"Building Stability Certificate", 
"Quantity & Completion certificate of Electrical wiring from recognized Authority" 
] 
}, 
{ 
0: "Electricity", 
1: "New Electricity Connection (LT)", 
2: "O/O Assistant Engineer, IPP, HQ", 
3: "30", 
dept_name: "Electricity", 
service_name: "New Electricity Connection (LT)", 
contact_point: "O/O Assistant Engineer, IPP, HQ", 
timeline: "30", 
docs: [ 
"Record of Rights Form 'F'", 
"Sketch Map", 
"Identity Proof" 
] 
}, 
{ 
0: "Electricity", 
1: "New Electricity Connection (HT)", 
2: "O/O Assistant Engineer, IPP, HQ", 
3: "45", 
dept_name: "Electricity", 
service_name: "New Electricity Connection (HT)", 
contact_point: "O/O Assistant Engineer, IPP, HQ", 
timeline: "45", 
docs: [ 
"Record of Rights Form 'F'", 
"Sketch Map", 
"Identity Proof" 
] 
}, 
{ 
0: "Electricity", 
1: "New Electricity Connection (Extra HT)", 
2: "O/O Assistant Engineer, IPP, HQ", 
3: "180", 
dept_name: "Electricity", 
service_name: "New Electricity Connection (Extra HT)", 
contact_point: "O/O Assistant Engineer, IPP, HQ", 
timeline: "180", 
docs: [ 
"Record of Rights Form 'F'", 
"Sketch Map", 
"Identity Proof" 
] 
}, 
{ 
0: "APWD", 
1: "Planning Permissin ", 
2: "PBMC/Concerned Panchayat", 
3: "15", 
dept_name: "APWD", 
service_name: "Planning Permissin ", 
contact_point: "PBMC/Concerned Panchayat", 
timeline: "15", 
docs: [ 
"Record of Rights Form 'F'", 
"Sketch Map", 
"Building Plan/Site Plan", 
"Statement of proposed Development", 
"Document of Ownership & title of Property", 
"Receipt of Payment of Application Fee" 
] 
}, 
{ 
0: "PBMC", 
1: "Planning Permissin ", 
2: "PBMC", 
3: "160", 
dept_name: "PBMC", 
service_name: "Planning Permissin ", 
contact_point: "PBMC", 
timeline: "160", 
docs: [ 
"Building Plan/Site Plan", 
"Document of Ownership & title of Property", 
"Form of Notice of Intention to errect a Building or to execute any work as prescribed in Appendix 'A'", 
"Form of notice of Completion Appendix 'E'", 
"Form of Occupancy Certificate Appendix 'F, G & H'", 
"Performa of details of Construction of Building around Port Blair Airport, Appendix I, IIA, IIB, IIC, IID, IIE & C" 
] 
}, 
{ 
0: "Labour", 
1: "Licence Under the Factories ACT, 1948", 
2: "O/O Labour Commissioner", 
3: "60", 
dept_name: "Labour", 
service_name: "Licence Under the Factories ACT, 1948", 
contact_point: "O/O Labour Commissioner", 
timeline: "60", 
docs: [ 
"Building Plan/Site Plan", 
"Receipt of Payment of Application Fee", 
"Site Map in the Scale (1cm : 20Mtrs)", 
"Flow chart of the Manufacturing Process" 
] 
}, 
{ 
0: "Labour", 
1: "Registration Under Contract Labour (R ", 
2: "O/O Labour Commissioner", 
3: "15", 
dept_name: "Labour", 
service_name: "Registration Under Contract Labour (R ", 
contact_point: "O/O Labour Commissioner", 
timeline: "15", 
docs: [ 
"Receipt of Payment of Application Fee", 
"Affidavit in Prescribed Format" 
] 
}, 
{ 
0: "Labour", 
1: "Registration Under A ", 
2: "O/O Labour Commissioner", 
3: "30", 
dept_name: "Labour", 
service_name: "Registration Under A ", 
contact_point: "O/O Labour Commissioner", 
timeline: "30", 
docs: [ 
"Form D and E as per Annexures" 
] 
}, 
{ 
0: "DC Office", 
1: "Land Conversion", 
2: "O/O Deputy Commissioner", 
3: "28", 
dept_name: "DC Office", 
service_name: "Land Conversion", 
contact_point: "O/O Deputy Commissioner", 
timeline: "28", 
docs: [ 
"Record of Rights Form 'F'", 
"Sketch Map", 
"Document of Ownership & title of Property", 
"Project Report", 
"Affidavit in Prescribed Format", 
"Site Map in the Scale (1cm : 20Mtrs)", 
"Photograph of the proposed site with the Signature" 
] 
}, 
{ 
0: "PCC", 
1: "Common Consent to Establish, Operate", 
2: "O/O A ", 
3: "90", 
dept_name: "PCC", 
service_name: "Common Consent to Establish, Operate", 
contact_point: "O/O A ", 
timeline: "90", 
docs: [ 
"Record of Rights Form 'F'", 
"Sketch Map", 
"Building Plan/Site Plan", 
"Document of Ownership & title of Property", 
"Notarized Affidavit in twenty rupees stamp paper or valuation certificate from Chartered Accountant giving details of Capital Investment including Land, Building and Plant & Machinery without depreciation", 
"Registration Certificate of DIC", 
"Project Report", 
"CRZ-Clearance/Environmental Clearance/Noc from Forest Department of from Revenue Authority showing the distance of the Building/Unit from High Tide Level (HTL)", 
"Copy of Permission granted for Ground water withdrawal from Competent Authority" 
] 
} 
] 

Ama veriler olmak istiyorum bölümleri tarafından düzenlenmiştir, örneğin:

elektrik borç iki kere gelmemelidir; elektrik borçlarının içinde başka bir dizide olmalı.

+0

"Foreach in foreach" (iç içe foreach) öğesini deneyebilirsiniz. –

+0

herhangi bir öneri ya da bunu yaparken bir yaklaşım ... –

+0

Bu nasıl * bu nasıl bir yaklaşım? – GolezTrol

cevap

0

Sadece bir örnek kod ekliyorum, lütfen kendiniz için değiştirin.

3 farklı tabloya sahip olduğumuzu ve bu tablolardan veri almamız ve json çıkışı yapmamız gerektiğini varsayalım. Burada örnek kod:

foreach ($table_one as $to) { 

    foreach($table_two as $tt) { 

     foreach($table_three as $ttr) { 

     $data[]  = array 
     (
     'value1' => $ttr['value1'], 
     'value2' => $tt['value2'], 
     'value3' => $to['value3'] 
     ); 
     } 
    } 
} 

$json = json_encode($data); 

Unutmayın, bu sadece bir örnektir. Kendiniz için değiştirmeyi unutmayın!

+0

Bu konuya yeni başlayanlar için lütfen bunu bana yapabilirsin. –

+0

Yaparsam, asla öğrenemeyeceksin. Sadece dene, yapabileceğine eminim. –

+0

ok lemme try ... güven için thnx ... bu yüzden bana bir php snippet rite verdin? –