Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Creating a search in multiple fields
Old 09-18-2009, 05:42 AM Creating a search in multiple fields
Junior Talker

Posts: 1
Name: ippbx
Trades: 0
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>
";
__________________

Please login or register to view this content. Registration is FREE
ippbx is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Creating a search in multiple fields
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.80978 seconds with 12 queries