DECLARE #xml xml=' <?xml version="1.0" encoding="UTF-8"?><text>
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
<th>f</th>
</tr>
</thead>
<tbody>
<tr>
<td>testa1</td>
<td>testb1</td>
<td>testc1</td>
<td>testd1</td>
<td>teste1</td>
<td>testf1</td>
</tr>
<tr>
<td>testa1</td>
<td>testb1</td>
<td>testc1</td>
<td>testd1</td>
<td>teste1</td>
<td>testf1</td>
</tr>
</tbody>
</table>
</text>'
SELECT
T.c.value('(tbody/tr/td)[1]','VARCHAR(100)') AS a
FROM
#xml.nodes('text/table[thead[tr[th="b"]]]') AS t(c)
This query selects only the first body contents from xml.
Here I want to select only the values under header b
Modifying the xpath as follows will do it:
SELECT T.c.value('/text/table/tbody/tr/td[position()=2]','VARCHAR(100)') AS a
Explanation:
Selects the second td element among a list of siblings.
Note:
Combine that with this SO answer to get:
SELECT T.c.value('/text/table/tbody/tr/td[position() = count(/text/table/tbody/tr/th[text() = "b"]/preceding-sibling::*)+1]','VARCHAR(100)') AS a
Related
I have to print a specific value based on column and row names.
Bt the problem is that columns position and rows position changes every time. And table data is dynamic, values are changing continuously. All the values are not constantmy dynamic web table is. and i want specific value of month April in year 2001.
Here is the sample table based on the attached screenshot.
<html>
<table id='table1' border=" 1px solid black">
<tr>
<th>Month/Year</th>
<th>2003</th>
<th>2004</th>
<th>2001</th>
<th>2005</th>
<th>2002</th>
</tr>
<tr>
<td>May</td>
<td>122</td>
<td>84</td>
<td>7777</td>
<td>12</td>
<td>122</td>
</tr>
<tr>
<td>Feb</td>
<td>45</td>
<td>445</td>
<td>565</td>
<td>222</td>
<td>122</td>
</tr>
<tr>
<td>April</td>
<td>3556</td>
<td>212</td>
<td>21</td>
<td>1546</td>
<td>855</td>
</tr>
</table>
<span>-----------------------------------------------</span>
<table id='table2' border=" 1px solid black">
<tr>
<th>Month/Year</th>
<th>2002</th>
<th>2001</th>
<th>2003</th>
<th>2004</th>
<th>2005</th>
</tr>
<tr>
<td>April</td>
<td>120</td>
<td>243</td>
<td>221</td>
<td>21</td>
<td>65</td>
</tr>
<tr>
<td>May</td>
<td>96</td>
<td>146</td>
<td>454</td>
<td>452</td>
<td>4566</td>
</tr>
<tr>
<td>March</td>
<td>788</td>
<td>139</td>
<td>10</td>
<td>1001</td>
<td>013</td>
</tr>
<tr>
<td>Feb</td>
<td>552</td>
<td>1245</td>
<td>545</td>
<td>41</td>
<td>41</td>
</tr>
</table>
</html>
Below is the xpath to get the value of "April/2001" from table 1.
//table[#id='table1']//td[position()=count(//th[normalize-space(.)='Month/Year']/preceding-sibling::th)+1 and normalize-space(.)='April']/ancestor::tr//td[position()=count(//table[#id='table1']//th[normalize-space(.)='2001']/preceding-sibling::th)+1]
And xpath to get the value of "April/2001" from table 2.
//table[#id='table2']//td[position()=count(//th[normalize-space(.)='Month/Year']/preceding-sibling::th)+1 and normalize-space(.)='April']/ancestor::tr//td[position()=count(//table[#id='table2']//th[normalize-space(.)='2001']/preceding-sibling::th)+1]
The only difference between the 2 xpaths' above is table id **//table[#id='tableX**. Please update the table locator as per your application values.
Let me know if this is helpful.
I need to find relation between original columns indexes and columns indexes after sorting in datatables .
say we have an ordinary html table :
<table id="namesTable">
<thead>
<th>First Name</th>
<th>Last Name</th>
</thead>
<tbody>
<tr>
<td>Jim</td>
<td>Andrew</td>
</tr>
<tr>
<td>Pedro</td>
<td>Rodriguez</td>
</tr>
<tr>
<td>Manau</td>
<td>Lara</td>
</tr>
</tbody>
</table>
after calling :
$('#namesTable').DataTable(
'order' : [[0 , 'Desc']]
);
is there any way to have like a dictionnary that says that index 0 is now2 and 1 is now 0 and 2 is now 1 after ordering ?
any help is welcome !
dataTables row().index() or rows().indexes() returns the original index, eg how the rows are ordered in the underlying HTML. To get the row index from the example above :
$('#namesTable tbody').on('click', 'tr', function () {
alert(table.row(this).index());
});
demo -> http://jsfiddle.net/d6tcLtha/
i'm trying to compare the content of two variables in order to return if variable1 != variable2.
I found some different examples, how to compare variables, but not how to use this with an operator.
First of all, i store text, wait 5 minutes and store text again. If the text is different, so the testis passed.
<tr>
<td>storeText</td>
<td>id=newsdiv_1</td>
<td>newsBox1</td>
</tr>
<!--wait 6 min for ajax update-->
<tr>
<td>pause</td>
<td>360000</td>
<td></td>
</tr>
<tr>
<td>storeText</td>
<td>id=newsdiv_1</td>
<td>newsBox2</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>${newsBox1}</td>
<td>regexp=!(${newsBox2})</td>
</tr>
verifyExpressionworks perfect in comparing if 2 variables are equal.
But the last test should work like this: if newsBox1!=newsBox2 than return true
You can do a verifyNotExpression, which is basically a not of the verifyExpression:
<tr>
<td>verifyNotExpression</td>
<td>${newsBox1}</td>
<td>${newsBox2}</td>
</tr>
I have one file, then for every file there are multiple comments about that file. I was able to successfully join the two tables, comments and files, however when I try to view the page where it displays the file and its comments, the page displays the name of file n times (n corresponds to the number of records of comments of that certain file).
How will I be able to display just once the file name as well as displaying the comments?
<table width="40%" align="center">
<?php foreach($rows as $file):?>
<tr>
<td width="70%" id="title"><?php echo $file->name; ?></td>
</tr>
<?php endforeach;?>
</table>
<table width="40%" align="center" frame="above" style="margin-top:10px; border-top-width:3px; border-top-color:#666666">
<?php foreach($rows as $file):?>
<tr>
<td width="15%"></td>
<td width="45%" id="name">FILESIZE:</td>
<td width="40%" id="txt3"><?php echo $file->size; ?></td>
</tr>
<tr>
<td></td>
<td id="name">DATE UPLOADED:</td>
<td id="txt3"><?php echo $file->dateUploaded;?></td>
</tr>
<?php endforeach;?>
</table>
<!--COMMENTS -->
<table align="center" frame="above" style="margin-top:10px; border-top-width:3px; border-top-color:#666666" width="40%">
<tr>
<td><h3>Comments</h3></td>
</tr>
<tr><?php foreach($rows as $comment):?>
<td><?php echo $comment->comm;?></td>
</tr><?php endforeach;?>
</table>
You can use
GROUP_CONCAT()
in your join.
SELECT person.id AS id, name, GROUP_CONCAT(role.role SEPARATOR ',') AS roles
FROM person
LEFT OUTER JOIN person_role ON person.id=person_role.person_id
LEFT OUTER JOIN role ON person_role.role_id=role.id
GROUP BY id
ORDER BY id;
is an example from a tutorial at
http://dev-loki.blogspot.com/2008/01/aggregate-join-results-with-mysql-using.html
can't give much better without seeing your schema.
EDIT: trying anyway.
SELECT files.*, GROUP_CONCAT(comments.comment SEPARATOR ',') as comments_list
FROM files
LEFT JOIN comments on files.id = comments.id
GROUP BY id
ORDER BY id
Adding onto orbit, in codeigniter if your using activerecord it would be:
(Sorry, I couldn't format code in a comment)
$this->db->select('person.id AS id, name, GROUP_CONCAT(role.role SEPARATOR ',') AS roles',false);
$this->db->from('person');
$this->db->join('person_role', 'person.id = person_role.person_id', 'left outer');
$this->db->join('role', 'person_role.role_id = role.id', 'left outer');
$this->db->group_by('id');
$this->db->order_by('id'):
$this->db->get();
well it looks like you're echoing the filename for each row that is returned
your rows are getting returned like
name | size | comment1
name | size | comment2
so just don't do foreach ($rows as $file) that will print out the filename each time, just change
<?php foreach($rows as $file):?>
<tr>
<td width="70%" id="title"><?php echo $file->name; ?></td>
</tr>
<?php endforeach;?>
to
<tr>
<td width="70%" id="title"><?php echo $rows[0]->name; ?></td>
</tr>
I have to create specific table in PHPTAL.
I have array like that:
$tab = array('item1', 'item2', 'item3', 'item4');
Final table should be look like that:
<table>
<tr>
<td>Item1</td>
<td>Item2</td>
</tr>
<tr>
<td>Item3</td>
<td>Item4</td>
</tr>
</table>
So I was trying use tal:condition width "repeat/item/odd" and "repeat/item/even" to fit < tr > tag in right place, but it not working that I want to.
Have you any ideas?
<tr tal:repeat="row php:array_chunk(tab, 2)">