Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts

    set empty table cells to hidden

    I have a query to retrieve data from multiple tables in a database and then show the results in an html table. The problem is that due to the layout of my query the data in the html table isn't aligned correctly. Therefore I want to set the empty cells to hidden so that they don't show up in the table and therefore align the data up correctly.

    Here is my query below to help understand what I am talking about:


    Code:
    $sql="SELECT CUST_ID, CUST_Forename, CUST_Surname, CUST_Email, CUST_Mobile, CUST_HomeNum,
    	CUST_AddressL1, CUST_AddressL2, CUST_AddressL3, CUST_Postcode, '&nbsp' as J_RefNum, '&nbsp' as MANU_Name, 
    	'&nbsp' as J_Model, '&nbsp' as OS_Name, '&nbsp' as J_ReceivedBy, '&nbsp' as J_DateRec, '&nbsp' as J_FaultDesc,
    	'&nbsp' as J_PassWinAdmin, '&nbsp' as J_DataRecYN, '&nbsp' as J_PowerSuppYN, '&nbsp' as JS_Status 
    	FROM Customers 
    	
    	WHERE (CUST_ID LIKE '%$criteria%') OR (CUST_Forename LIKE '%$criteria%') OR 
    	(CUST_Surname LIKE '%$criteria%') OR (CUST_Email LIKE '%$criteria%') OR 
    	(CUST_Mobile LIKE '%$criteria%') OR (CUST_HomeNum LIKE '%$criteria%')
    	OR (CUST_AddressL1 LIKE '%$criteria%') OR (CUST_AddressL2 LIKE '%$criteria%') OR 
    	(CUST_AddressL3 LIKE '%$criteria%') OR (CUST_Postcode LIKE '%$criteria%')
    	
    	UNION
    	SELECT '', '', '', '', '', '',
    	'', '', '', '', J_RefNum, '', J_Model, '', J_ReceivedBy, J_DateRec, J_FaultDesc, J_PassWinAdmin,
    	J_DataRecYN, J_PowerSuppYN,'' 
    	FROM Jobs 
    	
    	WHERE (J_RefNum LIKE '%$criteria%') OR (J_Model LIKE '%$criteria%') OR 
    	(J_ReceivedBy LIKE '%$criteria%') OR (J_DateRec LIKE '%$criteria%') OR 
    	(J_FaultDesc LIKE '%$criteria%') OR (J_PassWinAdmin LIKE '%$criteria%') 
    	OR (J_DataRecYN LIKE '%$criteria%') OR (J_PowerSuppYN LIKE '%$criteria%') 
    	
    	UNION
    	SELECT '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp',
    	'&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', MANU_Name, '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp',
    	'&nbsp', '&nbsp', '&nbsp' 
    	FROM Manufacturers
    	
    	WHERE (MANU_Name LIKE '%$criteria%')
    	
    	UNION
    	SELECT '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp',
    	'&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', OS_Name, '&nbsp', '&nbsp', '&nbsp', '&nbsp',
    	'&nbsp', '&nbsp', '&nbsp' 
    	FROM OperatingSystems
    	
    	WHERE (OS_Name LIKE '%$criteria%')
    	
    	UNION
    	SELECT '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp',
    	'&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp', '&nbsp',
    	'&nbsp', '&nbsp', 'JS_Status' 
    	FROM JobStatus
    	
    	WHERE (JS_Status LIKE '%$criteria%')";
    Here is the code to echo the data into the table with my attempt to hide the empty cells. Any suggestions would be greatly appreciated thanks.

    Code:
    while($row=mysql_fetch_assoc($result))
    {
    	echo "<tr>
    		<td style='empty-cells: hide'>{$row['CUST_ID']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_Forename']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_Surname']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_Email']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_Mobile']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_HomeNum']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_AddressL1']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_AddressL2']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_AddressL3']}</td>
    		<td style='empty-cells: hide'>{$row['CUST_Postcode']}</td>
    		<td style='empty-cells: hide'>{$row['J_RefNum']}</td>
    		<td style='empty-cells: hide'>{$row['MANU_Name']}</td>
    		<td style='empty-cells: hide'>{$row['J_Model']}</td>
    		<td style='empty-cells: hide'>{$row['OS_Name']}</td>
    		<td style='empty-cells: hide'>{$row['J_ReceivedBy']}</td>
    		<td style='empty-cells: hide'>{$row['J_DateRec']}</td>
    		<td style='empty-cells: hide'>{$row['J_FaultDesc']}</td>
    		<td style='empty-cells: hide'>{$row['J_PassWinAdmin']}</td>
    		<td style='empty-cells: hide'>{$row['J_DataRecYN']}</td>
    		<td style='empty-cells: hide'>{$row['J_PowerSuppYN']}</td>
    		<td style='empty-cells: hide'>{$row['JS_Status']}</td>
    		</tr>\n";
    	
    }

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    You just need to add the following into your CSS
    Code:
    table{
    empty-cells: hide;
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Appreciate the suggestion, still no joy though this is an example of the output that I get in the table

    table header table header table header
    data here ---data here

    --------------------------data here

    So for the third table header is there any way for me to remove the empty cell on the first row so that the data is lined up correctly.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,478
    Thanks
    6
    Thanked 981 Times in 954 Posts
    There appears to be some wrong math here in that a redundant cell is generated. The problem is in the PHP, though. You must only print as many data cells as there are header cells. Can you show us the generated HTML?

  • #5
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts

    No problem

    Code:
    <html>
    <body>
    <style type="text/css">
    table{
    empty-cells: hide;
    }
    </style>
    <table name='details' border='2'>
    <thead>
    	<tr>
    		<th>Customer ID</th>
    		<th>Forename</th>
    		<th>Surname</th>
    		<th>Email</th>
    		<th>Mobile Number</th> 
    		<th>Home Number</th>
    		<th>Address Line 1</th>
    		<th>Address Line 2</th>
    		<th>Address Line 3</th>
    		<th>Postcode</th>
    		<th>Job Reference Number</th>
    		<th>Manufacturer</th>
    		<th>Model</th>
    		<th>Operating System</th>
    		<th>Received By</th>
    		<th>Date Received</th>
    		<th>Fault Description</th>
    		<th>Password - Windows Admin</th>
    		<th>Data Recovery?</th>
    		<th>Power Supply?</th>
    		<th>Job Status</th>
    	</tr>
    </thead>
    <tbody>
    <tr><td>1</td><td>Daniel</td><td>Murphy</td><td>dm@hotmail.com</td><td>07512348906</td><td>02844123977</td><td>23 River Rd</td><td>Belfast</td><td>Co Antrim</td><td>BT33 TRL</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>2</td><td>Joe</td><td>Dunlop</td><td>eg@hotmail.com</td><td>07512347698</td><td>02844765122</td><td>22 Tea Rd</td><td>London</td><td>Surrey</td><td>BT33 TRL</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>1</td><td></td><td>Travel Mate</td><td></td><td>Ryan</td><td>2013-08-22</td><td>faulty hard drive</td><td>password</td><td>Yes</td><td>Yes</td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>2</td><td></td><td>765l</td><td></td><td>Ryan</td><td>2013-08-22</td><td>faulty hard drive</td><td>password</td><td>Yes</td><td>Yes</td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>Acer</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>Mesh Computers</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>Windows 2000</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>Windows XP</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>Not Started</td></tr></tbody>
    </table>
    </body>
    </html>

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,478
    Thanks
    6
    Thanked 981 Times in 954 Posts
    OK, let me reformat the table code for you so it becomes more obvious:
    Code:
    <table name='details' border='2'>
    	<thead>
    		<tr>
    			<th>Customer ID</th>
    			<th>Forename</th>
    			<th>Surname</th>
    			<th>Email</th>
    			<th>Mobile Number</th>
    			<th>Home Number</th>
    			<th>Address Line 1</th>
    			<th>Address Line 2</th>
    			<th>Address Line 3</th>
    			<th>Postcode</th>
    			<th>Job Reference Number</th>
    			<th>Manufacturer</th>
    			<th>Model</th>
    			<th>Operating System</th>
    			<th>Received By</th>
    			<th>Date Received</th>
    			<th>Fault Description</th>
    			<th>Password - Windows Admin</th>
    			<th>Data Recovery?</th>
    			<th>Power Supply?</th>
    			<th>Job Status</th>
    		</tr>
    	</thead>
    	<tbody>
    		<tr>
    			<td>1</td>
    			<td>Daniel</td>
    			<td>Murphy</td>
    			<td>dm@hotmail.com</td>
    			<td>07512348906</td>
    			<td>02844123977</td>
    			<td>23 River Rd</td>
    			<td>Belfast</td>
    			<td>Co Antrim</td>
    			<td>BT33 TRL</td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    		</tr>
    		<tr>
    			<td>2</td>
    			<td>Joe</td>
    			<td>Dunlop</td>
    			<td>eg@hotmail.com</td>
    			<td>07512347698</td>
    			<td>02844765122</td>
    			<td>22 Tea Rd</td>
    			<td>London</td>
    			<td>Surrey</td>
    			<td>BT33 TRL</td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td>1</td>
    			<td></td>
    			<td>Travel Mate</td>
    			<td></td>
    			<td>Ryan</td>
    			<td>2013-08-22</td>
    			<td>faulty hard drive</td>
    			<td>password</td>
    			<td>Yes</td>
    			<td>Yes</td>
    			<td></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td>2</td>
    			<td></td>
    			<td>765l</td>
    			<td></td>
    			<td>Ryan</td>
    			<td>2013-08-22</td>
    			<td>faulty hard drive</td>
    			<td>password</td>
    			<td>Yes</td>
    			<td>Yes</td>
    			<td></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td>Acer</td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td>Mesh Computers</td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td>Windows 2000</td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td>Windows XP</td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td></td>
    			<td>Not Started</td>
    		</tr>
    	</tbody>
    </table>
    Apparently there is something wrong in with the logic of retreiving the data and there is nothing CSS can do to fix that. Iím gonna move the thread to the MySQL forum.

  • Users who have thanked VIPStephan for this post:

    daniel0816 (09-09-2013)

  • #7
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    The problem is with my query with union everything has to be lined up correctly, surely there must be a way of excluding the empty table cells

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    UNION queries are for tables that have the same meaning/same structure data in them. In fact, the column names from the first SELECT statement are used as the column names for the results returned. If the columns in the first SELECT statement in your UNION query aren't what you intend for all the data, you are doing something wrong.

    UNION queries are not for retrieving rows from totally dissimilar tables.

    The goal of your query should be to retrieve the information that you want in the order that you want it. Your php code should only, and simply, need to output the data that the query returned. Trying to hid empty cells says that your query is not correct for the task you are trying to solve.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    daniel0816 (09-09-2013)

  • #9
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Sorry can you suggest an alternative solution am all out of ideas for this.
    Any suggestions will be greatly appreciated thanks.

  • #10
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    Your query would join the rows using whatever relationship you have setup between the tables. There are countless examples posted all over the Internet as this is a common task for RDBMS (relational database management systems.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    daniel0816 (09-09-2013)

  • #11
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Ok appreciate the help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •