Exemple
:
Récuperer
les mots clés du champ description
if description <> "" then
myarray = Split(description)
NbTabIndice_description=UBound(myarray) Compter
le nombre de mot c'est dire la dimension du tableau
end
if
Construire
la requette
If
description <> "" Then
Mettre AND ( uniquement pour le premier
tour)
Dim m_description, p_description
p_description = 0
m_description=0
For p_description=0 to NbTabIndice_description
if myarray(p_description)<>"" and m_description=0
then
whereStr = whereStr & "AND("
m_description=m_description+1
end if
NEXT
Construire
la requette pour chaque mot clé
For
p_description=0 to NbTabIndice_description
whereStr = whereStr & "p.description LIKE '%"&
myarray(p_description)&"%' AND "
NEXT
if Mid (whereStr , Len(whereStr)-3,4) = "AND " then
whereStr = Mid (whereStr , 1 , Len(whereStr) -4)
end if
Construire
le dernière parenthese
Dim q_description
q_description=0
for p_description=0 to NbTabIndice_description
if myarray(p_description) <> "" and q_description=
0 then
whereStr = whereStr & ")"
q_description=q_description+1
end if
next
End If
Résultat
de la requette si les mots clé indiqué dans le
champ de formulaire sont informatique ASP java
AND(p.description
LIKE '%informatique%' AND p.description LIKE '%ASP%' AND p.description
LIKE '%java%' )
Une
variante :
Si
vous désirez que l'internaute ait le choix entre des
mots clés qui utilise AND ou OR ( et ; ou)
vous mettez dans votre formulaire un bouton radio avec AND value=1
et OR value = 2
Voici
les modifs à faire au code précédent
For
p_titre=0 to NbTabIndice_titre
if operateur_logique = 1 then
whereStr = whereStr & "p.title LIKE '%"& myarrayTitre(p_titre)&"%'
AND "
else
whereStr = whereStr & "p.title LIKE '%"& myarrayTitre(p_titre)&"%'
OR "
end if
NEXT
if operateur_logique = 1 then
if Mid (whereStr , Len(whereStr)-3,4) = "AND
" then
whereStr = Mid (whereStr , 1 , Len(whereStr)
-4)
end if
else
if
Mid (whereStr , Len(whereStr)-2,3) = "OR " then
whereStr
= Mid (whereStr , 1 , Len(whereStr) -3)
end
if
end if
|