i want to order the second joined table according to price, to exaplain it more clear i will add a screenshot: http://s42.radikal.ru/i098/1108/87/66f19d915bbc.jpg the second table displays the prices: bayi 1, bayi 2, bayi 3, bayi 4 and liste fiyati, i want to rearrange em in another order starting from liste fiyati and ending on bayi 1. here is my query:
<cfquery name="get_products" datasource="#dsn3#">
SELECT P.PRODUCT_ID,P.PRODUCT_NAME,PS.MONEY,PR.PRICE,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK
FROM PRODUCT P
JOIN PRICE_STANDART PS ON P.PRODUCT_ID = PS.PRODUCT_ID
JOIN PRICE PR ON P.PRODUCT_ID = PR.PRODUCT_ID
JOIN #DSN2_ALIAS#.GET_STOCK_LAST GSL ON P.PRODUCT_ID = GSL.PRODUCT_ID
WHERE P.IS_SALES=1 AND P.IS_INTERNET=1 AND PS.PURCHASESALES=1 AND PS.PRICESTANDART_STATUS=1
AND PR.STARTDATE <= #now()# AND (PR.FINISHDATE >= #now()# OR PR.FINISHDATE IS NULL)
GROUP BY P.PRODUCT_ID,PR.PRICE,P.PRODUCT_NAME,PS.MONEY,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK
ORDER BY PS.PRICE DESC
</cfquery>
and the table:
<table cellpadding="3" cellspacing="1" class="color-border" width="100%">
<tr class="color-header">
<td><b>Ürün</b></td>
<td class="header_bold" width="80"><b>Marka</b></td>
<td class="header_bold" width="35"><b>Stok</b></td>
<td class="header_bold" width="35"><b>Yoldaki Stok</b></td>
<td class="header_bold" width="80">Bayı 4</td>
<td class="header_bold" width="80">Bayı 3</td>
<td class="header_bold" width="80">Bayı 2</td>
<td class="header_bold" width="80">Bayı 1</td>
<td class="header_bold" width="80">Liste fiyatı</td>
<td class="header_bold" width="25">Para</td>
</tr>
<cfoutput query="get_products" startrow="#attributes.startrow#" maxrows="#attributes.maxrows#" group="product_id">
<tr height="20" onMouseOver="this.className='color-light';" onMouseOut="this.className='color-row';" class="color-row">
<td>#product_name#</td>
<td align="center"><cfif len(brand_list)>#get_brands.brand_name[listfind(brand_list,brand_id,',')]#</cfif></td>
<td align="center">#PRODUCT_STOCK#</td>
<td align="center">#purchase_order_stock#</td>
<cfoutput><td align="center">#tlformat(price,2)#</td></cfoutput>
<td align="center">#MONEY#</td>
</tr>
<cfset toplam_stock = toplam_stock+product_stock>
<cfset toplam_order_stock = toplam_order_stock+purchase_order_stock>
</cfoutput>
<tr class="color-header">
<td colspan="2"></td>
<td align="center"><cfoutput>#toplam_stock#</cfoutput></td>
<td align="center"><cfoutput>#toplam_order_stock#</cfoutput></td>
<td colspan="12"></td>
</tr>
</table>
btw, the price i want to order is PRICE PR not the PRICE_STANDART PS, and thank you all for help!
You just need to add both ORDER BY statements:
ORDER BY P.PRODUCT_ID, PS.PRICE DESC
With ColdFusion grouping, make sure that you always sort by what you want to group by first, then you can sort by whatever you need inside the group.
But then change the
ORDER BY PS.PRICE DESC
to
ORDER BY PR.PRICE DESC
Surely?
If I understand what you're asking, you need to include all the cols from the GROUP BY in your ORDER BY statement first, and then add any other columns that you want to order by within those groupings.
But I'm afraid to say yor question isn't terribly clear.
--
Adam
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 am able to display the ItemID perfectly fine and the ItemIDs group together. When I try the SQL statement in MS Access the quantities add up perfectly fine but I can't manage to replicate this in HTML.
This is the code
<%
dim Con,rs, sql
set con = server.CreateObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")
Con.Open("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" & Server.MapPath("Database/Name.accdb"))
sql = "SELECT ItemID, SUM(Quantity) FROM tblCreatedItems GROUP BY ItemID ORDER BY tblCreatedItems.ItemID"
rs.open sql, Con
%>
<body>
<table width="467" align="center">
<th colspan="5"><strong>Items Sold</strong></th>
<tr>
<td width="119"><strong>ItemID</strong></td>
<td width="165"><strong>Quantity</strong></td>
</tr>
<tr>
<% while not rs.eof%>
<td><%=rs("ItemID")%></td>
<td>
<% dim sql2
set sql2=con.execute("SELECT SUM(Quantity) FROM tblCreatedItems GROUP BY ItemID ORDER BY tblCreatedItems.ItemID" )
response.Write(sql2)
%></td>
</tr>
<% rs.movenext
wend
%>
</table>
</body>
You are already grouping by the itemid in the first query, and don't need a second query to show the sum.
In your sql add an alias (a name to reference the field) to the SUM field:
change SUM(Quantity) to SUM(Quantity) as NoOfItems (or whatever you like, as an alias)
The sql statement becomes:
SELECT ItemID, SUM(Quantity) as NoOfItems
FROM tblCreatedItems
GROUP BY ItemID
ORDER BY tblCreatedItems.ItemID
And Then:
<td><%=rs("NoOfItems")%></td>
should show your sum field.
So, your table code becomes:
<table width="467" align="center">
<th colspan="5"><strong>Items Sold</strong></th>
<tr>
<td width="119"><strong>ItemID</strong></td>
<td width="165"><strong>Quantity</strong></td>
</tr>
<tr>
<% while not rs.eof%>
<td><%=rs("ItemID")%></td>
<td><%=rs("NoOfItems")%></td>
</tr>
<% rs.movenext
wend
%>
</table>
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
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)">