简体   繁体   中英

Display Table data from 3 sql tables and display with a php condition - Using full join

I'm new to PHP, so please bear with me. I am working on a database project at work, where I'm interning. I'm trying to display a table given that the data has been fetched from the database. I have 3 tables

Table vege_plant

  • uuid
  • name

Table vege_location

  • uuid
  • location

Table vege_data

  • uuid
  • vege_plants_uuid
  • vege_location_uuid
  • transect_num
  • quadrant_num
  • alive
  • dead

My PHP code looks like this:

<?php

       $sql = mysql_query('SELECT vege_data.*, vege_location.*, vege_plants.*
       FROM vege_data
       JOIN vege_location ON vege_location.uuid =vege_data.vege_location_uuid
       JOIN vege_plants ON vege_plants.uuid = vege_data.vege_plants_uuid;);
            echo '<table class = "table table-hover">
<thead>
    <tr>
        <th>Location</th>
        <th>Transect Number</th>
        <th>Quadrat Number</th>
        <th>Plant Name</th>
        <th>Alive</th>
        <th>Dead</th>
        <th>Action</th>
    </tr>
</thead>
<tbody>';
            $count = 1;    

while ($row = mysql_fetch_assoc($result)) {
            echo '<tr>';
            echo '<td contenteditable="true">';
            echo '<td>';
            echo $row['location'];
            echo '</td>';
            echo '</td>';
            echo '<td contenteditable="true">';
            echo $row['transect_num'];
            echo '</td>';
            echo '<td contenteditable="true">';
            echo $row['quadrant_num'];
            echo '</td>';
            echo '<td contenteditable="true">';
            echo $row['name'];
            echo '</td>';
            echo '<td contenteditable="true">';
            echo $row['alive'];
            echo '</td>';
            echo '<td>';
            echo $row['dead'];
            echo '</td>';
            echo '</tr>';
        }

However, it's failing to display, not alerting any errors. I don't know where I'm going wrong.

Try This there is a syntax error at line 1st single qoute missing

   $sql = mysql_query('SELECT vege_data.*, vege_location.*, vege_plants.*
   FROM vege_data
   JOIN vege_location ON vege_location.uuid =vege_data.vege_location_uuid
   JOIN vege_plants ON vege_plants.uuid = vege_data.vege_plants_uuid;');


while ($row = mysql_fetch_array($result)) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM