Replicating a table - html-table

I'm having trouble replicating this table. I'm confused with the rowspan and colspan. I would really appreciate it if someone helps.
Click here to view image of the table

Here you go:
<table>
<tr>
<td colspan="7">The Error Rate on Different Forms</td>
</tr>
<tr>
<td rowspan="2">Form name</td>
<td rowspan="2">A</td>
<td rowspan="2">B</td>
<td rowspan="2">Total Fields (X = A x B)</td>
<td rowspan="2">Fields with errors (Y)</td>
<td colspan="2">Error rate* (Y/X) x 100 (%)</td>
</tr>
<tr>
<td>X/Y</td>
<td>%age</td>
</tr>
<tr>
<td colspan="7">High Risk Errors</td>
</tr>
<!-- normal tr td -->
<tr>
<td colspan="7">Low Risk Error</td>
</tr>
<!-- normal tr td -->
</table>

Related

rowSpan hides rows

<table>
<tr> <td rowspan="2">1</td> <td>2</td> </tr>
<tr> <td rowspan="2">3</td> </tr>
<tr> <td>4</td> </tr>
</table>
seemingly only displays two rows:
The reason for hiding the second row [1 3] is, that the cells with text 1 and 3 are reduced in height. Is there a way to ensure, that the second row is visible in the display (not only in DOM)?
The problem gets clearer, if you look at the same table with an additional column:
<table>
<tr> <td rowspan="2">1</td> <td>2</td> <td>0</td> </tr>
<tr> <td rowspan="2">3</td> <td>0</td> </tr>
<tr> <td>4</td> <td>0</td> </tr>
</table>
which is displayed like:
You can add a height property to the row:
<table border=1>
<tr>
<td rowspan="2">1</td>
<td>2</td>
</tr>
<tr style="height: 1.5em">
<td rowspan="2">3</td>
</tr>
<tr>
<td>4</td>
</tr>
</table>
One suboptimal option could be to add an empty column:
<table>
<tr> <td rowspan="2">1</td> <td>2</td> <td class="void"></td> </tr>
<tr> <td rowspan="2">3</td> <td class="void"></td> </tr>
<tr> <td>4</td> <td class="void"></td> </tr>
</table>
CSS:
table,td {border:1px solid}
.void {height:1em;padding:0;border:0}
However, the spacing between columns leads to unnecessary space for the added column:
As this problem could be solved with padding-left for TD and a cellspacing of 0 for the table, this solution would not be general enough, so I'm still waiting for a good idea.

SQL Server, parse a text which has multiple lines of html code into a table

I have a skeleton of a code which I began to write for the following purpose:
use EAS
go
declare #entityID,int
declare #text,text
declare #col1,varchar --col1 is between <b>col1</b>
declare #col2,varchar --col2 are between >col2</td>
#entityID=entity_ID
#text = maAttributes_Text.value
#col1 = select SUBSTRING(#text,CHARINDEX('<b>',#text)+len('<b>'),
charindex('</b>',#text))
#col2 = select substring(#text, CHARINDEX('>',#text)+LEN('>'),charindex('</td>',#text))
begin
add to `table2` [entity_id], [caption], [value]
#entityID, #col1, #col2
end
I need to access a different table, table1, which contains fields entity_id, caption and value, as well as a few others which are unimportant.
entity_id | caption | value
----------|--------------|-------
12345 |Specifications| *html snippet*
What my code is supposed to do is, to find rows in table1 which have the value of 'Specifications' in field caption, then extract the entity_id value, store it, and then run a loop which takes all the rows of the html table and adds the info into another sql table.
For example, after running the code for one line of table1, table2 will look like as follows:
table2
entity_ID|Caption|Value
---------|-------|-----
12345 |length |10
12345 |width |10
12345 |height |10
et al.
Where all the information in table2 came from the html snippet which is stored in value field of table1.
My instincts tell me that I should use both a loop (I cannot make a loop in sql for the life of me) and the STRING_SPLIT function. However, I am not sure how to implement them.
After finishing the first row of table1, it will continue to the next row and the next row, as many rows WHERE caption in ('specifications')
EDIT: I understand my wording was pretty confusing. I will try to reexplain.
I have table1 which contains an ID number which is tied to an html snippet. The html snippet is the code for a table which contains many rows and two columns. My desired function will take the html snippet and parse it by row, and add it to table2 where the one ID number from table1 will be attached to the several rows of the html table. Therefore when the first few rows of the HTML SNIPPET are extracted, table2 will appear as so:
table2
entity_ID|Caption|Value
---------|-------|-----
12345 |length |10
12345 |width |10
12345 |height |10
wherein entity_ID is the unique ID number, and it is tied to several rows from within the HTML snippet. Caption is taken from col1 of the html snippet, and Value is taken from col2 of the html snippet.
EDIT 2:
A simple example of my situation:
table1
ID|Caption |Value
--|--------------|-----
1 |Specifications|*html snippet*
2 |Specifications|*html snippet2*
etc.
the code will take information from table1 and put it into `table2' as follows:
table2
ID|SpecName|Spec
--|--------|----
1 |Length |10
1 |Width |10
1 |Height |10
SpecName and Spec are fields from the html table that the html snippet created. Length, Width, Height are the information that the snippet is producing. 10, is the value for each of the SpecNames.
<table class="inline_sd_table"> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Accessories Optional</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Accommodates Ceiling Height</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ADA Compliance</b></td> <td class="inline_sd_even_cell">See Additional Information above</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Blower Air Mover Type</b></td> <td class="inline_sd_odd_cell">Fan</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Blower Included</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Boost Mode</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>CFM (Airflow)</b></td> <td class="inline_sd_even_cell">190</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Color/Finish</b></td> <td class="inline_sd_odd_cell">Almond</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Control Feature Filter Reminder</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Damper Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Delay Shut Off</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Digital Clock</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Dishwasher Safe Filters</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Duct Connector Size</b></td> <td class="inline_sd_odd_cell">3-1/4" x 10", 7" Round Non-Ducted</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ENERGY STARĀ® qualified</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Filter Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Filter Type</b></td> <td class="inline_sd_even_cell">Aluminum</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Flue Accommodates ceilings up to xx ft</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Heat Sentry - Temperature Sensor</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>HVI Certified</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Light Bulb Quantity</b></td> <td class="inline_sd_even_cell">1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Light Bulbs Included</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Lighting Function</b></td> <td class="inline_sd_even_cell">One-level</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Lighting Type</b></td> <td class="inline_sd_odd_cell">Incandescent</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Max Sones/100 CFM</b></td> <td class="inline_sd_even_cell">4.1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Minimum Height Above Cook Top</b></td> <td class="inline_sd_odd_cell">18"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Mounting Type</b></td> <td class="inline_sd_even_cell">Under Cabinet</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Nightlight</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Non-Stick Coated</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Depth (inches)</b></td> <td class="inline_sd_odd_cell">17-1/2"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Product Height (inches)</b></td> <td class="inline_sd_even_cell">6"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Width (inches)</b></td> <td class="inline_sd_odd_cell">42"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Rated Amps</b></td> <td class="inline_sd_even_cell">2.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Remote Control</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Horizontal Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Horizontal Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Round High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Round Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Switch Control Settings</b></td> <td class="inline_sd_even_cell">2</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Switch Style</b></td> <td class="inline_sd_odd_cell">Rocker</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Timer</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>UL Listed</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Voltage</b></td> <td class="inline_sd_even_cell">120</td> </tr> </table>
Your example is a little hard to follow, but does this help?
I modified a Parse/Split function to accept two non-like parameters. In this case '>' and '<'.
I should add, the TVF is very performant. The results are returned in 0.068 seconds.
Example
Declare #S varchar(max) = '<table class="inline_sd_table"> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Accessories Optional</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Accommodates Ceiling Height</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ADA Compliance</b></td> <td class="inline_sd_even_cell">See Additional Information above</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Blower Air Mover Type</b></td> <td class="inline_sd_odd_cell">Fan</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Blower Included</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Boost Mode</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>CFM (Airflow)</b></td> <td class="inline_sd_even_cell">190</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Color/Finish</b></td> <td class="inline_sd_odd_cell">Almond</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Control Feature Filter Reminder</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Damper Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Delay Shut Off</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Digital Clock</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Dishwasher Safe Filters</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Duct Connector Size</b></td> <td class="inline_sd_odd_cell">3-1/4" x 10", 7" Round Non-Ducted</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ENERGY STARĀ® qualified</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Filter Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Filter Type</b></td> <td class="inline_sd_even_cell">Aluminum</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Flue Accommodates ceilings up to xx ft</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Heat Sentry - Temperature Sensor</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>HVI Certified</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Light Bulb Quantity</b></td> <td class="inline_sd_even_cell">1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Light Bulbs Included</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Lighting Function</b></td> <td class="inline_sd_even_cell">One-level</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Lighting Type</b></td> <td class="inline_sd_odd_cell">Incandescent</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Max Sones/100 CFM</b></td> <td class="inline_sd_even_cell">4.1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Minimum Height Above Cook Top</b></td> <td class="inline_sd_odd_cell">18"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Mounting Type</b></td> <td class="inline_sd_even_cell">Under Cabinet</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Nightlight</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Non-Stick Coated</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Depth (inches)</b></td> <td class="inline_sd_odd_cell">17-1/2"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Product Height (inches)</b></td> <td class="inline_sd_even_cell">6"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Width (inches)</b></td> <td class="inline_sd_odd_cell">42"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Rated Amps</b></td> <td class="inline_sd_even_cell">2.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Remote Control</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Horizontal Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Horizontal Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Round High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Round Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Switch Control Settings</b></td> <td class="inline_sd_even_cell">2</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Switch Style</b></td> <td class="inline_sd_odd_cell">Rocker</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Timer</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>UL Listed</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Voltage</b></td> <td class="inline_sd_even_cell">120</td> </tr> </table> '
Select Item = max(case when RetCol=1 then RetVal end)
,Value = max(case when RetCol=0 then RetVal end)
From (
Select RetGrp=(Row_Number() over (Order By RetSeq)-1)/2
,RetCol=Row_Number() over (Order By RetSeq) % 2
,RetPos
,RetVal
From [dbo].[udf-Str-Extract](#S,'>','<')
Where RetVal>''
) A
Group By RetGrp
Order By RetGrp
Returns
The UDF if Interested
CREATE FUNCTION [dbo].[udf-Str-Extract] (#String varchar(max),#Delimiter1 varchar(100),#Delimiter2 varchar(100))
Returns Table
As
Return (
with cte1(N) As (Select 1 From (Values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) N(N)),
cte2(N) As (Select Top (IsNull(DataLength(#String),0)) Row_Number() over (Order By (Select NULL)) From (Select N=1 From cte1 N1,cte1 N2,cte1 N3,cte1 N4,cte1 N5,cte1 N6) A ),
cte3(N) As (Select 1 Union All Select t.N+DataLength(#Delimiter1) From cte2 t Where Substring(#String,t.N,DataLength(#Delimiter1)) = #Delimiter1),
cte4(N,L) As (Select S.N,IsNull(NullIf(CharIndex(#Delimiter1,#String,s.N),0)-S.N,8000) From cte3 S)
Select RetSeq = Row_Number() over (Order By N)
,RetPos = N
,RetVal = left(RetVal,charindex(#Delimiter2,RetVal)-1)
From (
Select *,RetVal = Substring(#String, N, L)
From cte4
) A
Where charindex(#Delimiter2,RetVal)>1
)
/*
Max Length of String 1MM characters
Declare #String varchar(max) = 'Dear [[FirstName]] [[LastName]], ...'
Select * From [dbo].[udf-Str-Extract] (#String,'[[',']]')
*/
EDIT - Illustration of Raw Results
If you were to simply run
Select * from [dbo].[udf-Str-Extract](#S,'>','<')
The Results would be:
What about this? Note, I had to update the HTML blob because it had an unencoded &, so I just manually changed it to &. But as long as that's set up, this should work:
declare #x xml = cast('<table class="inline_sd_table"> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Accessories Optional</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Accommodates Ceiling Height</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ADA Compliance</b></td> <td class="inline_sd_even_cell">See Additional Information above</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Blower Air Mover Type</b></td> <td class="inline_sd_odd_cell">Fan</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Blower Included</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Boost Mode</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>CFM (Airflow)</b></td> <td class="inline_sd_even_cell">190</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Color/Finish</b></td> <td class="inline_sd_odd_cell">Almond</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Control Feature Filter Reminder</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Damper Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Delay Shut Off</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Digital Clock</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Dishwasher Safe Filters</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Duct Connector Size</b></td> <td class="inline_sd_odd_cell">3-1/4" x 10", 7" Round Non-Ducted</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ENERGY STAR&reg; qualified</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Filter Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Filter Type</b></td> <td class="inline_sd_even_cell">Aluminum</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Flue Accommodates ceilings up to xx ft</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Heat Sentry - Temperature Sensor</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>HVI Certified</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Light Bulb Quantity</b></td> <td class="inline_sd_even_cell">1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Light Bulbs Included</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Lighting Function</b></td> <td class="inline_sd_even_cell">One-level</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Lighting Type</b></td> <td class="inline_sd_odd_cell">Incandescent</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Max Sones/100 CFM</b></td> <td class="inline_sd_even_cell">4.1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Minimum Height Above Cook Top</b></td> <td class="inline_sd_odd_cell">18"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Mounting Type</b></td> <td class="inline_sd_even_cell">Under Cabinet</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Nightlight</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Non-Stick Coated</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Depth (inches)</b></td> <td class="inline_sd_odd_cell">17-1/2"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Product Height (inches)</b></td> <td class="inline_sd_even_cell">6"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Width (inches)</b></td> <td class="inline_sd_odd_cell">42"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Rated Amps</b></td> <td class="inline_sd_even_cell">2.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Remote Control</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Horizontal Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Horizontal Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Round High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Round Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Switch Control Settings</b></td> <td class="inline_sd_even_cell">2</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Switch Style</b></td> <td class="inline_sd_odd_cell">Rocker</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Timer</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>UL Listed</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Voltage</b></td> <td class="inline_sd_even_cell">120</td> </tr> </table> ' as xml)
select
Name = t.c.value('(td/b)[1]', 'varchar(250)'),
Value = t.c.value('(td)[2]', 'varchar(250)')
from #x.nodes('/table/tr') as t(c)
Example of Using a TVF within a CROSS APPLY
Insert Into Table2
Select ID = A.Entity_ID
,B.*
From Table1 A
Cross Apply (
Select Top 10000
SpecName = max(case when RetCol=1 then RetVal end)
,Spec = max(case when RetCol=0 then RetVal end)
From (
Select RetGrp=(Row_Number() over (Order By RetSeq)-1)/2
,RetCol=Row_Number() over (Order By RetSeq) % 2
,RetPos
,RetVal
From [dbo].[udf-Str-Extract](A.value,'>','<')
Where RetVal>''
) B1
Group By RetGrp
Order By RetGrp
) B
Select * from Table2

Finding Duplicate Pairs in Excel

So I have this summary sheet. It contains data from multiple workbooks going across.
It's not like this question, because what I'm trying to do is find all the inconsistant pairs of data in this worksheet going across and highlight them.
Here is a fiddle that explains what I want to accomplish. I have a large worksheet, and would like to compare the first 2 rows with the next 2 rows etc. throughout the worksheet. Below is an HTML representation of what I am trying to accomplish.
<table class="tg">
<tr>
<th class="tg-031e">#INT1</th>
<th class="tg-031e">#INT1</th>
<th class="tg-031e">#INT2</th>
<th class="tg-031e">#INT2</th>
<th class="tg-031e">#INT3</th>
<th class="tg-031e">#INT3</th>
</tr>
<tr>
<td class="tg-031e">Apples</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Bananas</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Apples</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Bananas</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Peppers</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Bananas</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Peppers</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Pomegranite</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Peppers</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Pomegranite</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Nuts</td>
<td class="tg-031e">YYYYYNN</td>
<td class="tg-031e">Pomegranite</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Nuts</td>
<td class="tg-031e">YYYYYYNN</td>
<td class="tg-031e">Smango</td>
<td class="tg-031e">NNNYYNNN</td>
<td class="tg-031e">Nuts</td>
<td class="tg-031e">NNNYNNNN</td>
</tr>
<tr>
<td class="tg-zl7m">Oranges</td>
<td class="tg-zl7m">YYYYNNNN</td> <!-- this oranges is different from... -->
<td class="tg-031e">Blackberries</td>
<td class="tg-031e">NNNYYNNNN</td>
<td class="tg-zl7m">Oranges</td>
<td class="tg-zl7m">NNNYYNNN</td> <!-- ...this one -->
</tr>
<tr>
<td class="tg-031e">Smango</td>
<td class="tg-031e">NNNYYNNN</td>
<td class="tg-031e">Berries</td>
<td class="tg-031e">YYNYNNNN</td>
<td class="tg-031e">Smango</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Skiwi</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-031e">Beer</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-031e">Steaks</td>
<td class="tg-031e">Y</td>
</tr>
<tr>
<td class="tg-031e">Steaks</td>
<td class="tg-031e">Y</td>
<td class="tg-031e">Blueberries</td>
<td class="tg-031e">YNNYNNNN</td>
<td class="tg-031e">Steaksauce</td>
<td class="tg-031e">NNNYNNNN</td>
</tr>
<tr>
<td class="tg-zl7m">Steaksauce</td>
<td class="tg-zl7m">YYNYNNNN</td>
<td class="tg-031e">Blucheese</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-zl7m">Apricot</td>
<td class="tg-zl7m">YYYYNNNN</td>
</tr>
<tr>
<td class="tg-031e">Apricot</td>
<td class="tg-031e">YYYYNNNN</td>
<td class="tg-031e">Blackberries</td>
<td class="tg-031e">NNNYNNNN</td>
<td class="tg-031e">Milkshake</td>
<td class="tg-031e">NNNYNNNN</td>
</tr>
</table>
I have tried VBA solutions and also conditional formatting. Any solution that will make this work is greatly appreciated.
Thank you.
I think this array formula should work:-
=SUM(ISODD(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12<>B2))
if the table starts in A1, this can be applied as conditional formatting from A2 to E12 and will highlight the left-hand (fruit) cell of inconsistent pair of cells.
Then you can use a similar formula to highlight the right-hand cell of each pair:-
=SUM(ISEVEN(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12<>B2))
Apply this from B2 to F12.
Note that Smango are highlighted because they are in an inconsistent group (although they are also in a consistent group).
Here is the alternative approach (as suggested) of highlighting the consistent groups:-
The formulae are
=SUM(ISODD(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12=B2))>1
and
=SUM(ISEVEN(COLUMN())*($A$2:$E$12=A2)*($B$2:$F$12=B2))>1
to be applied as before.
The sum this time will always be at least one because each pair of cells will match with itself, so the '>' sign is to find if there are any matches with other pairs of cells.

image uploaded to database but unable to display the image

Im using the simpleform to upload the file image
<tr>
<td align="right">Photo</td>
<td><input type="file"size="30" name="photo" /></td>
</tr>
then here is my php file..Im using mysql_fetch_array
row[6] is my photo...
// retrieves a row data and returns it as an associative array
while($row=mysql_fetch_array($result)){
echo "<table border='1' align='center' class='table_background'>
<tr>
<td align='left' width=100>UserName=</td>
<td align='left' width='400'></td>
</tr>
<tr>
<td align='left' width=100>Title=</td>
<td align='left' width='400'>$row[1]</td>
</tr>
<tr>
<td align='left'width=100>Category=</td>
<td align='left'width='400'>$row[2]</td>
</tr>
<tr>
<td align='left'width=100>Description=</td>
<td align='left'width='400'>$row[3]</td>
</tr>
<tr>
<td align='left'width=100>State=</td>
<td align='left'width='400'>$row[4]</td>
</tr>
<tr>
<td align='left'width=100>Photo=</td>
<td align='left'width='400'>$row[5]</td>
</tr>
<tr>
<td align='left'width=100>Date=</td>
<td align='left'width='200'>$row[6]</td>
</tr>
<br>
}
<br>
<br>
</table>";
}
In my database I use Blob as the type of image ... the image is successful upload to my database
but just display the image file name...
blob is a string so you have to display id a bit different
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row[6] ).'"/>';

Beautifulsoup replace colspan=2 with single col

I'm trying to parse data from rows which occasionally have a colspan=2 which spoils my ability to target data to extract.
What I'd like to do is remove the 'colspan=2' from the table element every time it occurs:
#replace
<td colspan="2" class="time">10:00 AM</td>
#with
<td>635</td>
Is this possible? And can I work it into a conditional if then else?
Here's a more verbose example:
<table>
<tr class="playerRow even">
<td class="pos">1</td>
<td><span class="rank"></span> -</td>
<td class="player"><p class="playerName">John doe</p></td>
<td class="background">X</td>
<td>345</td> #THIS ELEMENT FREQUENT
<td></td>
<td></td>
<td></td>
<td></td>
<td style=""></td>
</tr><
<tr class="playerRow odd">
<td class="pos">1</td>
<td><span class="rank"></span> -</td>
<td class="player"><p class="playerName">John doe</p></td>
<td class="background">X</td>
<td colspan="2" class="myClass" style="">3:15 PM</td> #THIS ELEMENT OCCASIONAL
<td></td>
<td></td>
<td></td>
<td></td>
<td style=""></td>
</tr>
<tr class="playerRow odd">
<td class="pos">1</td>
<td><span class="rank"></span> -</td>
<td class="player"><p class="playerName">John doe</p></td>
<td class="background">X</td>
<td>22</td> #THIS ELEMENT FREQUENT
<td></td>
<td></td>
<td></td>
<td></td>
<td style=""></td>
</tr>
</table>
So whenever I come across the colspan I'd like to replace it with a plain td, so it doesn't shunt the row elements across and mess up my count.
This will convert:
<td colspan="2" class="myClass" style="">3:15 PM</td>
to:
<td>3:15 PM</td>
from bs4 import BeautifulSoup
bs = BeautifulSoup(html)
for x in bs.findAll("td"):
if "colspan" in x.attrs:
x.attrs = {}
Do you want it to remove the value also?