Search Engine Forums - Creating a search in multiple fields
Search Engine Forums
Search Engine Forums
Discussion Forum of SEO and Webmaster Related Topics


Our Website Web
[ Submit Express Home ] :: [ Forums Home ] :: [ Register ]
 

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in
Creating a search in multiple fields

 
Post new topic   Reply to topic    Search Engine Forum Forum Index -> Everything Else
View previous topic :: View next topic  
Author Message
mangopalaya



Joined: 07 Aug 2009
Posts: 2
Location: Italy

PostPosted: Mon Aug 10, 2009 4:42 am    Post subject: Creating a search in multiple fields Reply with quote

I have used your search-keyword.php tutorial and have tried to modify it to allow for search in multiple fields. I have a table that list the following:

id, mentee1, senior1, junior1, mentee2, senior2, junior2, mentee3, senior3, junior3, mentee4, senior4, junior4, mentee5, senior5, junior5 (and a few others that are not important)

Except for the "id" all are names of individuals and can show up in all fields and more than one field ie J Smith can be a mentee1 and a junior3.

I would like to search for J Smith and find him in all the entries.

Here is how I have wrongly modified the code:

Code: Select all
<?php
include("connectdb.php");

$todo=$_POST['todo'];
if(isset($todo) and $todo=="search"){
$search_text=$_POST['search_text'];
$type=$_POST['type'];

$search_text=ltrim($search_text);
$search_text=rtrim($search_text);

if($type<>"any"){
$query="select * from test where mentee1 and senior1 and junior1 and mentee2 and senior2 and junior2 and mentee3 and senior3 and junior3 and mentee4 and senior4 and junior4 and mentee5 and senior5 and junior5='$search_text'";
}else{
$kt=split(" ",$search_text);//Breaking the string to array of words
// Now let us generate the sql
while(list($key,$val)=each($kt)){
if($val<>" " and strlen($val) > 0){$q .= " mentee1 and senior1 and junior1 and mentee2 and senior2 and junior2 and mentee3 and senior3 and junior3 and mentee4 and senior4 and junior4 and mentee5 and senior5 and junior5 like '%$val%' or ";}

}// end of while
$q=substr($q,0,(strLen($q)-3));
// this will remove the last or from the string.
$query="select * from test where $q ";
} // end of if else based on type value
echo $query;
echo "<br><br>";
$nt=mysql_query($query);
echo mysql_error();
while($row=mysql_fetch_array($nt)){

<? $display_block .="
<tr><td>$id</td><td>$mentee1</td><td align=center>$senior1</td><td align=center>$junior1</td><td>$mentee2</td><td>$senior2</td><td>$junior2</td><td>$mentee3</td><td>$senior3</td><td>$junior3</td><td>$mentee4</td><td>$senior4</td><td>$junior4</td><td>$mentee5</td><td>$senior5</td><td>$junior5</td></tr>
";

while($row=mysql_fetch_assoc($result)){

echo "$display_block";

echo '<td width="50"><a href="update.php?id='.$row['id'].'">Update</a></td></tr></table>';

echo "<hr>";
}
// End if form submitted

}else{
echo "<form method=post action=''><input type=hidden name=todo value=search>
<input type=text name=search_text ><input type=submit value=Search><br>
</form>
";
_________________
Call center software
Back to top
View user's profile Send private message
rayter



Joined: 03 Mar 2009
Posts: 1079
Location: United States

PostPosted: Tue Aug 25, 2009 11:02 am    Post subject: Reply with quote

Are you sure these codes are wrongly modified? They worked when I tested them.
_________________
Delta-Larm Sheet Metal Fabricating
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Search Engine Forum Forum Index -> Everything Else All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group