2016-12-13 10 views
0

これは私のコードです。私はデータベーステーブルのitemIDに基づいて出力を印刷したいと思います。配列とループを使って各itemIDの出力をそれぞれどのように出力するのですか?これを行う最善の方法は何ですか?今のPHPでselect文を使用して配列をループする方法

  <?php $result=mysql_query("select * from item where itemID='2'")or die (mysql_error()); 
     $get_row=mysql_fetch_array($result); 
    ?> 

      <?php echo $get_row['No']; ?>.<?php echo $get_row['Item']; ?> :<?php echo $get_row['Unit']; ?> unit 


    <br> 
    </br> 

    <center> 
     <table border="1" width="1000" height="80"> 



      <thead> 
       <tr> 


        <th>Nama</th> 
        <th>Jenama</th> 
        <th>Model</th> 
        <th>No_Siri</th> 
        <th>Tagging</th> 
        <th>Tarikh_Diterima</th> 
        <th>Remarks</th> 

       </tr> 
      </thead> 
      <tbody> 

       <?php $emp_query=mysql_query("select * from service_record where itemID='2' order by Nama"); 
        while($row=mysql_fetch_array($emp_query)){ $id=$row['service_record_id']; $emp=$row['itemID']; ?> 

        <tr class="del<?php echo $id ?>"> 
         <?php 
          $result=mysql_query("select * from item where itemID='2'")or die(mysql_error()); 
          $row_emp=mysql_fetch_array($result); 
         ?> 
         <td><?php echo $row['Nama']; ?></td> 
         <td><?php echo $row['Jenama']; ?></td> 
         <td><?php echo $row['Model']; ?></td> 
         <td><?php echo $row['No_Siri']; ?></td> 
         <td><?php echo $row['Tagging']; ?></td> 
         <td><?php echo $row['Tarikh_Diterima']; ?></td> 
         <td><?php echo $row['Remarks']; ?></td> 




        </tr> 
        <?php }?> 
      </tbody> 
     </table> 
    </center> 

      <br> 
</br> 

    <br> 
</br> 


<?php 
$result=mysql_query("select * from item where itemID='1'") or die(mysql_error()); 
$get_row=mysql_fetch_array($result); 
?> 
<?php echo $get_row['No']; ?>.<?php echo $get_row['Item']; ?> :<?php echo $get_row['Unit']; ?> unit 

<br> 
</br> 
<center> 
    <table border="1" width="1000" height="80"> 
     <thead> 
      <tr> 
       <th>Nama</th> 
       <th>Jenama</th> 
       <th>Model</th> 
       <th>No_Siri</th> 
       <th>Tagging</th> 
       <th>Tarikh_Diterima</th> 
       <th>Remarks</th> 
      </tr> 
      </thead> 
      <tbody> 
       <?php 
       $emp_query=mysql_query("select * from service_record where itemID='1' order by Nama"); 
       while($row=mysql_fetch_array($emp_query)){ 
        $id=$row['service_record_id']; 
        $emp=$row['itemID']; 
       ?> 
       <tr class="del<?php echo $id ?>"> 
        <?php 
        $result=mysql_query("select * from item where itemID='1'")or die(mysql_error()); 
        $row_emp=mysql_fetch_array($result); 
        ?> 
        <td><?php echo $row['Nama']; ?></td> 
         <td><?php echo $row['Jenama']; ?></td> 
         <td><?php echo $row['Model']; ?></td> 
         <td><?php echo $row['No_Siri']; ?></td> 
         <td><?php echo $row['Tagging']; ?></td> 
         <td><?php echo $row['Tarikh_Diterima']; ?></td> 
         <td><?php echo $row['Remarks']; ?></td> 
        </tr> 
は、iがアイテムID = 1、アイテムID = 2などによるいずれかによってコード1を書き。私はあなたがそれを維持する必要がある他のループ中に内部に保つことができるよりも唯一の1つの行のデータを持っている場合は、1つ

this is the example of picture that i want the output to display

+1

何が問題なのですか。あなたは一番いい方法は何ですか? –

+0

どこを閉じますか? –

+0

コーディングでは、コーディングにどのように組み込むかわからないので、コーディングではループと配列を使用しませんでした。 – Hann

答えて

0

ことによってそれを1つずつ記述せずにデータベースに出力表示すべてのItemIDを作る方法を知りませんループの外側にあります。

   <tr> 
       while($row=mysql_fetch_array($emp_query)) 
       { 
       $id=$row['service_record_id']; 
       $emp=$row['itemID']; 
       // use itemID='$emp' instead of itemID='1' 
        $result=mysql_query("select * from item where itemID='$emp'")or die(mysql_error()); 
        $row_emp=mysql_fetch_array($result); 
        ?> 
        <td><?php echo $row['Nama']; ?></td> 
         <td><?php echo $row['Jenama']; ?></td> 
         <td><?php echo $row['Model']; ?></td> 
         <td><?php echo $row['No_Siri']; ?></td> 
         <td><?php echo $row['Tagging']; ?></td> 
         <td><?php echo $row['Tarikh_Diterima']; ?></td> 
         <td><?php echo $row['Remarks']; ?></td> 

       <?php } ?> 
       </tr> 
+0

詳細を説明する方法がわかりません。あなたが気にしないなら、コードの下に私が付いている絵を見ることができます。それは私が持ちたい出力です。 – Hann

+0

更新されたコードを使用してください。更新コード – kashif

+0

を確認してもうまくいきません – Hann

関連する問題