Making Search Engin using PHP & MySQL to search in DB

Reply

Join Date: Dec 2006
Posts: 1
Reputation: web_gost is an unknown quantity at this point 
Solved Threads: 0
web_gost web_gost is offline Offline
Newbie Poster

Making Search Engin using PHP & MySQL to search in DB

 
0
  #1
Dec 12th, 2006
Hi
Iam new with php & making searching module for client.for searching i select two values from DROP DOWN list i.e: Category & City, Third value is the search string entered by the user like Hussain & co.
Now wht i want is that , it giv me results by searching in whole DB depending up category & City. In simple words first ir search for "Hussain", then "&" then "co".
It'll be good if it cater special characters.
Looking forward for ur kind response.
  1.  
  2. //////////index.php/////////////
  3.  
  4. <form name="s_frm" method="post" action="search.php">
  5. <input type="text" name="search_txt" maxlength="20">
  6. <select name="kat">
  7. <option value="">--Select--</option>
  8. <option value="Firm" >Firm</option>
  9. <option value="Product">Product
  10. </option>
  11.  
  12. <option value="Project">Project
  13. </option>
  14.  
  15. <option value="Service">Service
  16. </option>
  17. </select>
  18. <select name="sity">
  19. <option value="">---City---</option>
  20. <option value="Islamabad">Islamabad
  21. </option>
  22. <option value="Rawalpindi">Rawalpindi
  23. </option>
  24. </select>
  25.  
  26. <input type="submit" name="search" value="Search">
  27. </form>
  28.  
  29. /////////////////////////////////////////////////////////////
  30.  
  31. //////////search.php///////////////////////////////////
  32. <?php
  33. //make connection with DB
  34. include ("connect2db.php");
  35. $search_txt=$_REQUEST["search_txt"];
  36. $kat=$_REQUEST["kat"];
  37. $sity=$_REQUEST["sity"];
  38.  
  39. //trim whitespace from the stored variable i.e from left & right.
  40. $trimmed = trim($search_txt);
  41.  
  42. switch($kat)
  43. {
  44.  
  45. case 'Firm':
  46. {
  47. if($sity=="")
  48. {
  49. $query=mysql_query("select distinct(firm.fi_name), firm.fi_reg_name, firm.fi_views,firm_info.f_description
  50. FROM firm,firm_info
  51. where firm.fi_name like '%$trimmed%'
  52. AND firm_info.fi_name like '%$trimmed%'
  53. "); //OR firm.fi_reg_name like '%$trimmed%'
  54.  
  55. break;
  56.  
  57.  
  58. }
  59. else
  60. {
  61.  
  62. $query=mysql_query("select distinct(firm.fi_name), firm.fi_reg_name, firm.fi_views,firm_info.f_description
  63. FROM firm,firm_info
  64. where firm.fi_name like '%$trimmed%'
  65. AND firm_info.fi_name like '%$trimmed%'
  66.  
  67. AND firm_info.f_city like '%$sity%'
  68.  
  69. ");
  70. break;
  71.  
  72. }
  73. }
  74. case 'Product':
  75. {
  76. if($sity=="")
  77. {
  78.  
  79. $query=mysql_query("select pd_description,fi_name,pd_name,pd_view
  80. from product_detail
  81. where (pd_description like '%$trimmed%'
  82. or pd_name like '%$trimmed%')
  83. ");
  84. break;
  85.  
  86.  
  87. }
  88. else
  89. {
  90.  
  91. $query=mysql_query("select pd_description,fi_name,pd_name,pd_view
  92. from product_detail
  93. where (pd_description like '%$trimmed%' or pd_name like '%$trimmed%')
  94. AND pd_city='$sity'
  95. ");
  96. break;
  97.  
  98. }
  99. }
  100. case 'Project':
  101. {
  102. if($sity=="")
  103. {
  104. $query=mysql_query("select pro_description,fi_name,pro_name,pro_views
  105. FROM projects
  106. where (pro_description like '%$trimmed%' or pro_name like '%$trimmed%')
  107. ");
  108.  
  109. break;
  110. }
  111. else
  112. {
  113. $query=mysql_query("select pro_description,fi_name,pro_name,pro_views
  114. FROM projects
  115. where (pro_description like '%$trimmed%' or pro_name like '%$trimmed%')
  116. AND pro_city='$sity'
  117. ");
  118. break;
  119. }
  120. }
  121. case 'Service':
  122. {
  123. if($sity=="")
  124. {
  125. $query=mysql_query("select svc_description,fi_name,svc_title,svc_views
  126. FROM services
  127. where (svc_description like '%$trimmed%' or svc_title like '%$trimmed%')
  128. ");
  129.  
  130. break;
  131. }
  132. else
  133. {
  134. $query=mysql_query("select svc_description,fi_name,svc_title,svc_views
  135. FROM services
  136. where (svc_description like '%$trimmed%' or svc_title like '%$trimmed%')
  137. AND svc_city='$sity'
  138. ");
  139. break;
  140. }
  141. }
  142. }
  143.  
  144. while($data=mysql_fetch_array($query))
  145. {
  146. if($kat=="Firm")
  147. {
  148. $fi_name = $data["fi_name"];
  149. $fi_reg_name = $data["fi_reg_name"];
  150. $description = $data["f_description"];
  151. }
  152. if($kat=="Product")
  153. {
  154. $fi_name = $data["fi_name"];
  155. $name = $data["pd_name"];
  156. $description = $data["pd_description"];
  157. }
  158. if($kat=="Project")
  159. {
  160. $fi_name = $data["fi_name"];
  161. $name = $data["pro_name"];
  162. $description = $data["pro_description"];
  163. }
  164. if($kat=="Service")
  165. {
  166. $fi_name = $data["fi_name"];
  167. $name = $data["svc_title"];
  168. $description = $data["svc_description"];
  169. }
  170.  
  171. echo $fi_name. "&nbsp&nbsp(&nbsp" . $name . "&nbsp)";
  172. ?>
  173.  
  174. ///////////////////////////////////////////////////////
ALLAH Bless all of us n our families.
Usman
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2133 | Replies: 0
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC