943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 186
  • PHP RSS
Sep 2nd, 2010
0

Multiple search fields results

Expand Post »
hello,
i have something like this
search:_______ search1:___________ submit btn

how can i search for something from the same table in the database considering both search fields?

I've tried this code nut it doesn't work.
thanks

php Syntax (Toggle Plain Text)
  1. if($search == '')
  2. {
  3. $smarty->assign('Error','Please enter any string!');
  4. $z=1;
  5. }
  6. elseif($type == 'like')
  7. {
  8. $sql = 'SELECT * FROM topic WHERE Title LIKE '."'$search%'".' AND Title1 LIKE '."'$search1%'";
  9. }
  10. elseif($type == 'exact')
  11. {
  12. $sql = 'SELECT * FROM topic WHERE MATCH (Title) AGAINST ("'.$search.'") AND (Title1) AGAINST ("'.$search1.'")';
Last edited by patrioticcow; Sep 2nd, 2010 at 4:01 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
patrioticcow is offline Offline
3 posts
since Sep 2010
Sep 2nd, 2010
0
Re: Multiple search fields results
You used double quotes, instead of single.
PHP Syntax (Toggle Plain Text)
  1. if($search == '')
  2. {
  3. $smarty->assign('Error','Please enter any string!');
  4. $z=1;
  5. }
  6. elseif($type == 'like')
  7. {
  8. $sql = "SELECT * FROM topic WHERE Title LIKE '$search%' AND Title1 LIKE '$search1%'";
  9. }
  10. elseif($type == 'exact')
  11. {
  12. $sql = "SELECT * FROM topic WHERE MATCH (Title) AGAINST ('$search') AND (Title1) AGAINST ('$search1')";
  13. }
Last edited by pritaeas; Sep 2nd, 2010 at 10:15 am.
Sponsor
Featured Poster
Reputation Points: 546
Solved Threads: 717
Bite my shiny metal ass!
pritaeas is offline Offline
4,143 posts
since Jul 2006
Sep 2nd, 2010
0
Re: Multiple search fields results
What doesn't work exactly? You get a PHP or Sql error code or you get no results when you should be?

Edit: ok, you got a solution now :] Ignore this message :]
Last edited by Daiva; Sep 2nd, 2010 at 10:20 am.
Reputation Points: 14
Solved Threads: 9
Light Poster
Daiva is offline Offline
37 posts
since May 2009
Sep 2nd, 2010
0
Re: Multiple search fields results
Click to Expand / Collapse  Quote originally posted by Daiva ...
What doesn't work exactly? You get a PHP or Sql error code or you get no results when you should be?

Edit: ok, you got a solution now :] Ignore this message :]
thanks for the reply

the single quotes improved the search, but.
it looks like the each search field finds results independent from each other. I want them to work together and the result to contain what is search in both fields

and i get no errors php or sql errors.
Last edited by patrioticcow; Sep 2nd, 2010 at 10:39 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
patrioticcow is offline Offline
3 posts
since Sep 2010
Sep 2nd, 2010
0
Re: Multiple search fields results
hello.
i believe i fix it.
ill explin my results on the code
php Syntax (Toggle Plain Text)
  1. //this is the first search field
  2. if($search == '')
  3. {
  4. $smarty->assign('Error','Please enter an departure location!');
  5. $z=1;
  6. }
  7. //this is the second search field
  8. elseif($search1 == '')
  9. {
  10. $smarty->assign('Error','Please enter any destination!');
  11. $z=1;
  12. }
  13. //both search fields are selecting and matching the search words from the table "topic" with the fields "Title1" and "Title2"
  14. elseif($type == 'like')
  15. {
  16. $sql = "SELECT * FROM topic WHERE Title LIKE '$search%' AND Title1 LIKE '$search1%'";
  17. }
  18. elseif($type == 'exact')
  19. {
  20. $sql = "SELECT * FROM topic WHERE MATCH (Title) AGAINST ('$search') AND (Title1) AGAINST ('$search1')";
  21. //$sql .= ' UNION ';
  22. }
  23. //this is what solved my problem. i replace the $search with $search1.
  24. if($tag == 'tag' && $z!= 1)
  25. {
  26. $sql .= ' OR Tag LIKE "%'.$search1.'%"';
  27. }
  28. //and off course the double quotes thing by pritaeas:)

ill keep u all posted if any problem occurs in the nearest future
thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
patrioticcow is offline Offline
3 posts
since Sep 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: combo box's problem
Next Thread in PHP Forum Timeline: passing variables





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC