|
Posted by Ja NE on 11/10/05 14:38
I'm trying to write a search script for my site. basic serch is fine, I
can search for some word in one or other or third table, column... no
problem, but now I would like to serch for name and family name of
rtegistered users. so I need to search in more than one table. for one
or two or even more words (imagine you are looking for Jan Michael
Bellay) do I need query with AND... o.k., here is what I have done so
far:
$search = $_POST['serach']
if(isset($search)) {
// spliting search terms
$oneword = explode(" ", $search);
// counting numbers of terms to search
$all=str_word_count($search);
foreach($oneword as $number => $searchoneword) {
// forming sql block if there is more than one term to search
if($number < ($all-1)) {
$sqlblock = "uname LIKE %$searchoneword% OR
name LIKE %$searchoneword% OR
famname LIKE %$searchoneword% AND ";
}
// forming sql block if there is one or is the last one to search
else {
$sqlblock = "uname LIKE %$searchoneword% OR
name LIKE %$searchoneword% OR
famname LIKE %$searchoneword% ";
}
}
// and now... WHAT?
}
I have tried all I know. and that isn't much.
tried to create array in foreach loop, couldnt get out what I wanted.
tried to write a function of above, to get out something with return()
but don't know what to do later...
I can echo what I want, but that isn't that... I need to put those block
together(!) in one variable which I will later use in slq query like:
$query = "SELECT $alltogether ORDER BY id ACS";
anyone can suggest me what to do?
tnx
--
Ja NE
http://fotozine.org/?omen=janimir
--
Navigation:
[Reply to this message]
|