Jump to content

Nested Tables Populated from DB


SalientAnimal

Recommended Posts

Hi All,

 

I'm trying to get my head wrapped around how to create a Table from a DB. I have no issues getting the information, and all the data is pulling through as expected. I just cant seem to get my layout of my table right.

 

I have tried to draw a diagram of how I would like my table to be displayed. The left hand side of the table is pretty much static with the amount of rows always being static.

 

Here there are 5 rows with headings, the 3 row / nested table returning an address section with 5 address rows, and the last row will return the contact number row with 2 contact numbers.

 

The biggest complication is on the right hand side of the table which shows a list of hyperlinked documents, however each document type (heading) may have anywhere from 1 - 10 documents. And I would need this section of the table to expand as each row with a new document is returned. I have attached the layout diagram.

 

My current code for this section looks as follows (The code below is still a work in progress):

echo "<div class='row'>";
echo "<div class='col-md-12'>";
echo     "<div class='box box-primary'>";
echo		"<div class='box-header with-border'>";
echo        "<h3 class='box-title'>Outlet Details</h3>";
echo "<table border = '0'>";
echo 

	"
		<tr>
			<th width='50%'>Outlet Details</th>
			<th width='50%'>Outlet Documentation</th>			
		</tr>
	
	";	

while($row = mysqli_fetch_array($result)) 
{
	$store_code = $row['store_code'];
	$outlet_name = $row['outlet_name'];
	$address_0 = $row['address_0'];
	$address_1 = $row['address_1'];
	$address_2 = $row['address_2'];
	$address_3 = $row['address_3'];
	$address_4 = $row['address_4'];	
	$license = $row['scanned_license'];		
	$permit_renewal = $row['scanned_permit_renewal'];	
	$identity_document = $row['scanned_identity_document'];	
	$other_document = $row['scanned_other_document'];	
	
	echo		"<tr>
					<td>".$store_code."</td>
					<td><a href='uploads/".$license."'>".$license."</a></td>
								
				</tr>";
				
	echo		"<tr>	
					<td>".$outlet_name."</td>
					<td><a href='uploads/".$permit_renewal."'>".$permit_renewal."</a></td>
				</tr>";

	echo		"<tr>				
					<td>".$address_0."</td>
					<td><a href='uploads/".$identity_document."'>".$identity_document."</a></td>		
				</tr>";	
				
	echo		"<tr>				
					<td>".$address_1."</td>
					<td><a href='uploads/".$other_document."'>".$other_document."</a></td>
				</tr>";					
				
} 

post-93553-0-98447100-1486554990_thumb.png

Link to comment
Share on other sites

		
$result = mysqli_query($link,$sqlsearch)or die(mysqli_error());

while($row = mysqli_fetch_array($result)) 
{
	$store_code = $row['store_code'];
	$outlet_name = $row['outlet_name'];
	$address_0 = $row['address_0'];
	$address_1 = $row['address_1'];
	$address_2 = $row['address_2'];
	$address_3 = $row['address_3'];
	$address_4 = $row['address_4'];	
	$contact_number_1 = $row['contact_number_1'];	
	$contact_number_2 = $row['contact_number_2'];	
	$license = $row['scanned_license'];		
	$permit_renewal = $row['scanned_permit_renewal'];	
	$identity_document = $row['scanned_identity_document'];	
	$other_document = $row['scanned_other_document'];	
	
echo "<div class='row'>";
echo "<div class='col-md-12'>";
echo     "<div class='box box-primary'>";
echo		"<div class='box-header with-border'>";
echo        "<h3 class='box-title'>Outlet Details</h3>";
echo "<table>
  <tr>
      	<th>Outlet Details</th>
    	<th>Outlet Documentation</th>
   </tr>  
   <tr>
   		<td>
        <table>

        	<tr>
          		<th>Store Code</th>
            </tr>
            <tr>
          		<td>".$store_code."</td>
        	</tr>
        	<tr>
          		<th>Store Name</th>
            </tr>
            <tr>
				<td>".$outlet_name."</td>
        	</tr>  
        	<tr>
          		<th>Store Address</th>
            </tr>
            <tr>
				<td>".$address_0."</td>
        	</tr>  
	        <tr>
				<td>".$address_1."</td>
        	</tr> 
            <tr>
				<td>".$address_2."</td>
        	</tr> 
            <tr>
				<td>".$address_3."</td>
        	</tr>  
            <tr>
				<td>".$address_4."</td>
        	</tr>  
        	<tr>
          		<th>Contact Person</th>
            </tr>
            <tr>
          		<td>Jim</td>
        	</tr>  
        	<tr>
          		<th>Contact Number</th>
            </tr>
            <tr>
				<td>".$contact_number_1."</td>
        	</tr>
            <tr>
				<td>".$contact_number_2."</td>
        	</tr>

      </table>        
      </td>
    		<td>
        <table>

        	<tr>
          		<th>License</th>
            </tr>
            <tr>
				<td><a href='uploads/".$license."'>".$license."</a></td>
        	</tr>
        	<tr>
          		<th>Permit Renewal</th>
            </tr>
            <tr>
				<td><a href='uploads/".$permit_renewal."'>".$permit_renewal."</a></td>
        	</tr>  
        	<tr>
          		<th>Identity Document</th>
            </tr>
            <tr>
				<td><a href='uploads/".$identity_document."'>".$identity_document."</a></td>	
        	</tr>  
        	<tr>
          		<th>Other Documents</th>
            </tr>
            <tr>
				<td><a href='uploads/".$other_document."'>".$other_document."</a></td>
        	</tr>  
        	<tr>
          		<th>Reference Number</th>
            </tr>
            <tr>
          		<td>HSA0123456</td>
        	</tr>
            <tr>
          		<td>HSA0123457</td>
        	</tr>

      </table>        
      </td>  		
</table>
	";	
				
				
} 

echo "</table>";
mysqli_close($link);

Some code improvements made

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.