test si une valeur existe dans un tableau
Bonjour, est ce que vous connaissez une fonction qui permer de savoir si une fonction existe dans un tableau ou non ? sinon comment puis je faire ?:?
tester si une valeur existe dans un tableau
Code:
<%if(rs.getInt("Id_Ress")=(ress_tr[i])){ out.println("checked"); } %>
, je veux tester la valeur rs.getInt("Id_Ress") si elle existe dans le tableau ress_tr[i] ?
tester si une valeur existe dans un tableau
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| <HTML><!-- InstanceBegin template="/Templates/model.dwt.jsp" codeOutsideHTMLIsLocked="false" -->
<%@ include file="inc_connexion_auth.jsp" %>
<HEAD>
<!-- InstanceBeginEditable name="doctitle" -->
<TITLE>Modification équipe</TITLE>
<script language="javascript" src="script/gen_validatorv2.js"></script>
<!-- InstanceEndEditable -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<style type="text/css">
<!--
body {
background-image: url(images/back.gif);
background-repeat: repeat;
}
-->
</style></HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<TABLE WIDTH=800 BORDER=0 align="center" CELLPADDING=4 CELLSPACING=0 bgcolor="#FFFFFF" id="Tableau_01" style="border:solid 1px #99CC66">
<TR>
<TD>
<IMG SRC="images/index_01.jpg" WIDTH=800 HEIGHT=147 ALT=""></TD>
</TR>
<TR>
<TD height="361" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col">menu</th>
</tr>
<tr>
<td bgcolor="#FFFFFF"><!-- InstanceBeginEditable name="contenu" -->
<%
String choix = request.getParameter("choix");
String requete="SELECT * FROM equipe WHERE Id_Eqp="+choix;
rs = st.executeQuery(requete);
rs.first();// normalement se positionne avant la première ligne donc on doit se positionner sur la 1ere ligne
%>
<table width="100%" height="283" border="0" cellpadding="0" cellspacing="0">
<tr><td height="33"><TABLE WIDTH="43%" align="center"><tr><td class="titre">Modification d'une équipe : </td></tr></TABLE></td></tr>
<tr>
<td height="40"><form action="Trmodifequipe.jsp" method="post" name="modifequipe">
<br><br>
<table width="43%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="ligne2">
<td width="34%" class="labels">Nom equipe </td>
<td width="9%"> </td>
<td width="57%">
<input name="znomeqp" type="text" class="zcontenu" id="znomeqp" value="<%=rs.getString("Nom_Eqp") %>"></td>
</tr>
<tr class="ligne1">
<td class="labels">Descriprion</td>
<td> </td>
<td><input name="zdesceqp" type="text" class="zcontenu" value="<%=rs.getString("Desc_Eqp") %>"></td>
</tr>
<tr class="ligne2">
<td> </td>
<td> </td>
<td><input name="choix" type="hidden" id="choix" value="<%=request.getParameter("choix")%>"></td></tr>
<tr class="ligne1">
<td colspan="3">
<%
String requete1="SELECT Id_Ress FROM travailler where Id_Eqp="+ choix;
rs = st.executeQuery(requete1);
int h = 0;
int ress_tr[];
ress_tr = new int[10];
while(rs.next())
{
ress_tr[h++]=rs.getInt("Id_Ress");
}
String requete2="SELECT * FROM departement as d,service as s,ressource as r where d.Id_Depart=s.Id_Depart and s.Id_Serv=r.Id_Serv";
rs = st.executeQuery(requete2);
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="ligne1">
<tr class="vide">
<td> <div align="center">
<%
String color;
rs.last();
int i=0;
int total=rs.getRow();
if(total==0) {out.println(" Votre table ne contient aucun enregistrement ! ");
}
else {
rs.beforeFirst();
%>
</div></td></tr>
<tr bgcolor="#294C9E">
<td width="10%"> </td>
<td width="29%" class="head" ><div align="center">Employé</div></td>
<td width="28%" class="head" ><div align="center">Service
</th>
</div>
<td width="33%" class="head"><div align="center">Département</div></td>
</tr>
<tr>
<td height="80" colspan="4" align="left" valign="top">
<div id="Layer2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%
while(rs.next()){
if(i%2==0){ color="#B4D292";
}else{ color="F2FED6";
}
%>
<TR bgcolor="<%=color %>">
<TD width="21%">
<input name="choix<%=i %>" type="checkbox" value="<%=rs.getInt("Id_Ress") %>"<%if(rs.getInt("Id_Ress")==ress_tr[i]){ out.println("checked"); } %>><%=ress_tr[i] %></TD>
<TD width="27%"><div align="left"><%=rs.getString("Mat_Ress") %></div></TD>
<TD width="33%"><div align="left"><%=rs.getString("Nom_Serv") %></div></TD>
<TD width="19%"><div align="left"><%=rs.getString("Nom_Depart") %></div></TD>
</TR>
<%
i=rs.getRow();
} %>
</table>
</div> </td>
</tr>
<%
}
%>
<tr bgcolor="#FFFFFF">
<td height="10"><a href="equipe.jsp"><img src="images/retour.gif" width="18" height="19" border="0"></a><input name="nbelem" type="hidden" value="<%=i %>"></td>
<td height="10"> </td>
<td height="10"> </td>
<td height="10"><table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="48%" scope="col"><input name="Submit" type="submit" class="submit" value="Modifier"></td>
<td width="41%" scope="col"> </td>
<td width="11%"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form></td>
</tr>
<tr>
</tr>
</table>
<script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("modifequipe");
frmvalidator.addValidation("znomeqp","req","Nom equipe : champ obligatoire");
frmvalidator.addValidation("zdesceqp","req","Ditinguez vos equipe ! ");
</script>
<!-- InstanceEndEditable --></td>
</tr>
</table></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/index_03.jpg" WIDTH=800 HEIGHT=92 ALT=""></TD>
</TR>
</TABLE>
<!-- End ImageReady Slices -->
</BODY>
<!-- InstanceEnd --></HTML> |
tester si une valeur existe
j'ai deux requete la premiere c'est a partir de la table travailler qui me retourne un nombre de ressource et une deuxième de la table ressource qui me retourne tous ressource, je dois comparer si une ressource de la dexième table appartient a l'ensemble des ressource retourné par la premiere requete que j'ai stocké dans le tableau ress_tr ? c'est ca mon but !
tester si une valeur existe
merci kore61 pour ton aide voila j'ai pu résoudre le problème autrement j'ai eu le résultat souhaité en faisant ceci :
Code:
1 2 3 4 5 6 7 8 9
| <TD width="21%">
<input name="choix<%=i %>" type="checkbox" value="<%=rs.getInt("Id_Ress") %>"<%
for(i=0;i<ress_tr.length;i++)
{
if(rs.getInt("Id_Ress")==ress_tr[i]){
out.println("checked");
break;}
}
%>></TD> |
mais j'aimerais bien utilisé la meme chose avec binarysearch() ! :(