I have next table:
<table border="1">
<tbody>
<tr>
<th>Created By</th>
<th>Modified</th>
<th>Status</th>
</tr>
<tr>
<td>Mr. John</td>
<td>COMPLETE</td>
<td>PENDING</td>
</tr>
<tr>
<td>Mr. Lorem</td>
<td>COMPLETE</td>
<td>COMPLETE</td>
</tr>
</tbody>
</table>
How to select TD with COMPLETE status under Status TH?
How to select TR with COMPLETE status under Status TH?
How to select TD with COMPLETE status under Status TH?
//td[
normalize-space() = 'COMPLETE' and
count(preceding-sibling::td) = count(
ancestor::tbody/tr/th[normalize-space() = 'Status']/preceding-sibling::th
)
]
How to select TR with COMPLETE status under Status TH?
I'll leave this as an exercise.
With your table as :
Created | Modified | Status
----------------------------
Mr.John COMPLETE PENDING
Mr.Lorem COMPLETE COMPLETE
and from your questions 1. and 2.
You want for 1 : //table/tbody/tr/td[3][.='COMPLETE']
for 2 : //table/tbody/tr/td[3][.='COMPLETE']/parent::tr
Related
Table A
id
fullname
branch_code
Table B
id
branch_code
branch_name
I want to show list Table A with their branch name
here is the relation in table A
public function Branch () {
return $this->belongsTo('App\Model\Branch','branch_code','branch_code');
}
here is the controller
$TableA= TableA::orderBy('created_at','ASC')->get();
here is my blade
#foreach($TableAas $data)
<tr>
<td>{{ $i }}</td>
<td>{{$data->fullname}}</td>
<td>{{$data->Branch->branch_name}}</td>
</tr>
#endforeach
actually it works. but when i debug, i saw many duplicate queries like this
select top 1 * from [users] where [users].[branch_code] = '1001'
select top 1 * from [users] where [users].[branch_code] = '1002'
39.46ms
view::index:267
is there any way to make the query more simple and fast?
thank u
use with to load relation
$TableA= TableA::with('Branch')->orderBy('created_at','ASC')->get();
check EagerLoading problem and N+1 problem
How to get the job_id of the user_id linked to the employee_id
user_id_job = fields.Char(? string='User Job')
i just got the answer
<t t-foreach="request.env['hr.employee'].search([('user_id', '=', user.id)])" t-as="obj">
<t t-esc="obj.job_id.name"/>
</t>
I have three tables
"congers(code_conger primary key,date_depart,date_retour,duree)"
and
"ouvriers_congers(#idouvrier, #idconger)"
and
"ouvriers(matricule,nom,prenom)"
what I want is get the data from table congers with their OUVRIER "nom" and "prenom" and grouped by the idconger
<% ResultSet rsS = st.executeQuery("select o.matricule,o.nom,o.prenom, c.*, oc.* from ouvriers o, congers c, ouvriers_conger oc where c.code_conger = oc.idconger and oc.idouvrier = o.matricule");
while(rsS.next()){
int cd = rsS.getInt("code_conger");
%>
<tr>
<td><%= cd %></td>
<td><%= rsS.getDate("date_depart") %></td>
<td><%= rsS.getDate("date_retour") %></td>
<td><%= rsS.getInt("duree") %></td>
<td><%= rsS.getString("nom") %></td>
</tr>
<% } %>
but it show me the data like this
1 05/01/2015 05/05/2015 4 adil
1 05/01/2015 05/05/2015 4 souf
2 08/20/2015 08/30/2015 9 smith
as you see the result isn't groupped by the "code_conger"
I tried this to group it :
select o.*, c.*, oc.idconger,oc.idouvrier from ouvriers o, congers c, ouvriers_conger oc where c.code_conger = oc.idconger and oc.idouvrier = o.matricule group by oc.idconger
it give me an error : ORA-00979: not a GROUP BY expression
the result I want to get is :
1 05/01/2015 05/05/2015 4 -adil
-souf
2 08/20/2015 08/30/2015 9 smith
here is the DDL Statement for testing purpose
create table congers
(
code_conger NUMBER(5) PRIMARY KEY,
date_depart DATE DEFAULT (sysdate),
date_retour DATE DEFAULT (sysdate),
duree NUMBER(5)
);
create table ouvriers_congers
(
idouvrier NUMBER(5),
idconger NUMBER(5),
CONSTRAINT ouvriers_congers_pk PRIMARY KEY (idouvrier, idconger)
);
create table ouvriers
(
matricule NUMBER(5) PRIMARY KEY,
nom VARCHAR2(15),
prenom VARCHAR2(15)
);
INSERT INTO congers VALUES (1,to_date('05/01/2015','MM/DD/YYYY'),
to_date('05/05/2015','MM/DD/YYYY'),
4);
INSERT INTO congers VALUES (2,to_date('08/20/2015','MM/DD/YYYY'),
to_date('08/30/2015','MM/DD/YYYY'),
9);
INSERT INTO ouvriers VALUES (1,'adil','adil');
INSERT INTO ouvriers VALUES (2,'souf','souf');
INSERT INTO ouvriers VALUES (3,'smith','smith');
INSERT INTO ouvriers_congers VALUES (1,1);
INSERT INTO ouvriers_congers VALUES (2,1);
INSERT INTO ouvriers_congers VALUES (3,2);
I solved it my self :
<tbody>
<%
Statement st2 = Connect.connecter();
ResultSet rsS = st.executeQuery("select * from congers");
while(rsS.next()){
int cd = rsS.getInt("code_conger");
%>
<tr>
<td><%= cd %></td>
<td><%= rsS.getDate("date_depart") %></td>
<td><%= rsS.getDate("date_retour") %></td>
<td><%= rsS.getInt("duree") %></td>
<td>
<%
ResultSet rs2 = st2.executeQuery("select o.nom,o.prenom,o.matricule from ouvriers o,ouvriers_conger oc where oc.idconger = "+cd+" and oc.idouvrier = o.matricule");
while(rs2.next()){
out.print("- "+rs2.getString("nom")+" "+rs2.getString("prenom")+"<br />");
}
%>
</td>
<td style="width:200px !important;"><center><img alt="Modifier" src="img/edit.png" /> <img alt="Supprimer" src="img/delete.png" /></center></td>
</tr>
<% } %>
</tbody>
here I keep it here in case someone else needs it one day
you can use LISTAGG from oracle: http://www.techonthenet.com/oracle/functions/listagg.php
select
OC.IDCONGER,
C.DATE_DEPART,
C.DATE_RETOUR,
C.DUREE,
LISTAGG(o.nom||' '||O.PRENOM,',') WITHIN GROUP(ORDER BY O.NOM) AS ouvriers
FROM
congers C,
ouvriers_congers OC,
ouvriers O
WHERE
OC.IDCONGER = C.CODE_CONGER
AND OC.idouvrier = O.matricule
group by (OC.idconger,C.DATE_DEPART,C.DATE_RETOUR,C.DUREE)
or use FOR XML in MSSQL https://msdn.microsoft.com/it-it/library/ms178107.aspx
or use GROUP_CONCAT() from mysql: http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html#function_group-concat
ps: you should paginate your data so you don't get 1203487187124 results when your database gets big
Instead of doing never end copy past between 2 joomla 2.5 website (I want to copy past their modul and articles)
Phpmyadmin :
How can I copy past a single or multiple row (article, module) from one jrm_content to jasso_content (they have both exactly the same colons type)
I know how to select rows and to import them, but after...? (I changed the id are different exept for some the Asset ID is it a problem?
Thanks a lot!
What's wrong with queries like this?
INSERT INTO tableNew
(col1,col2,col3,col4,col5)
(
SELECT
col1,col2,col3,col4,col5
FROM tableOld
)
select from tablename where table name.primary key = table name.foreign key
<?php
$sname=$_POST['srname'];
$link=mysql_connect("localhost","root","") or die("Cannot Connect to the database!");
mysql_select_db("human_resource",$link) or die ("Cannot select the database!");
$query="SELECT * FROM employee WHERE fname='$sname'";
$resource=mysql_query($query,$link);
echo "
<table align=\"center\" border=\"1\">
<tr>
<td><b>FName</b></td> <td><b>lname</b></td><td><b></b></td><td><b>Department</b></td></tr> ";
while($result=mysql_fetch_array($resource))
{
echo "<tr><td>".$result[1]."</td><td>".$result[2]."</td><td>".$result[3]."</td></tr>";
}
echo "</table>";
?>
I have the following table and I am trying to display the sum of p_total along with all other records in the table. I have managed to display the total amount but if I display it, only values of the fist row of the table shows up. Although the sum of p_total is showing correctly as 600 .
Could you please tell me where is the problem in my code below:
Thanks in advance :)
My DB Table:
p_id p_name p_quantity p_rate p_total user_id
1 Pepsi 12 30 360 1
2 Hot Breads 12 20 240 1
I have the following code in my model
$this->db->select('*,SUM(temporary_table.p_total AS Total');
$this->db->from('temporary_table');
$this->db->where('user_id',$user_id);
$getData = $this->db->get('');
if($getData->num_rows() > 0) {
return $getData->result_array();
}
else {
return null;
}
This is my controller:
$this->load->model('mod_sales');
$data['records']= $this->mod_sales->add_to_temporary_table($user_id);
My View:
foreach ($records as $row)
{
<td><?php echo $row['p_name'];?></td>
<td><?php echo $row['p_quantity'];?></td>
<td><?php echo $row['p_rate'];?></td>
<td><?php echo $row['p_total'];?></td>
}
<?php echo $row['Total'];?>
You have a total and separate list.
$this->db->select_sum('total_price');
$this->db->from('order');
$this->db->where('dates BETWEEN DATE_ADD(NOW(), INTERVAL -7 DAY) AND NOW() ');
$query=$this->db->get();
$data['total']=$query->row()->total_price;
$this->db->select('*');
$this->db->from('order');
$this->db->where('dates BETWEEN DATE_ADD(NOW(), INTERVAL -7 DAY) AND NOW()');
$query=$this->db->get();
$data['count']=$query->num_rows();
Output:
Array (
[total] => 2759
[count] => 5
)
In your View:
$total_sum=0;
foreach ($records as $row){
<td><?php echo $row['p_name'];?></td>
<td><?php echo $row['p_quantity'];?></td>
<td><?php echo $row['p_rate'];?></td>
<td><?php echo $row['p_total'];?></td>
$total_sum+=$row['p_total'];
}
<?php echo $total_sum;?>
You're missing GROUP BY clause.
As I understand, you want this:
SELECT *, SUM(p_total) FROM temporary_table WHERE user_id = ... GROUP BY p_id
Not familiar with CodeIgniter, but guessing you need this line after "where":
$this->db->group_by('p_id');