• User avatar
  • User avatar
#614
I want to join two tables to display the information in many tables like this.

Below is the picture of my tables in database. From the tables in database i want to display it like the picture below in one page according to itemID.

9fac26bc33d562f357b544fe3a0085f71ad3ae3c.PNG
9fac26bc33d562f357b544fe3a0085f71ad3ae3c.PNG (290.5 KiB) Viewed 317 times


For now, i make it manually one by one. So it cannot display all the tables by itself. This is my code

Code: Select all<?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>
                    <?php }?>
            </tbody>
        </table>
    </center>

    <br>
</br>
      <br>
</br>


            <?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='3'")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='3' 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='3'")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>


</div>
erbhaveshkumar123 liked this
#620
@HannHanna, You can make use of "foreach" function in order to loop the repetitive part of the code and hence same the manual effort to type same set of code again and again.

Here is a dummy program, to help you understand better,
Code: Select all<?php

$rows_array = Query("SELECT id FROM `table1` "); // fetch multiple rows from database as array

   foreach($rows_array as $row){

      $rows = Query("SELECT * FROM `table2` WHERE `id`='".$row['id']."' ");
      echo print_r($rows);

   }

?>

yes, thanks for the infomation

Hello Thank u for this opportunity u will help us […]

Hello Thank u for this opportunity u will help us […]

GIVEAWAY: GET FREE $5 SEOCLERKS COUPON TO BUY SEO SERVICES @ SEOClerks.com