PageRenderTime 322ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/public/searchresult2.php

https://bitbucket.org/ayudh_das/khaugali.com
PHP | 412 lines | 398 code | 8 blank | 6 comment | 20 complexity | 0807cb7d8a7ebdf6257c987f394bad6d MD5 | raw file
  1. <?php
  2. require_once 'session.php';
  3. require_once '../include/util_functions.php';
  4. require_once '../include/db_functions.php';
  5. if(!(isset($_GET['location'])
  6. && isset($_GET['city'])
  7. && isset($_GET['search_key'])
  8. && isset($_GET['submit']))){
  9. redirectTo('home.php');
  10. }
  11. $connection = dbConnect();
  12. $location = $_GET['location'];
  13. $city = $_GET['city'];
  14. $searchKey= trim($_GET['search_key']);
  15. $initDat = array();
  16. if($searchKey == ''){
  17. if($city == 'All cities'){
  18. //echo 'all cities and all locations';
  19. $query = "select * from restaurant";
  20. $resultset = mysql_query($query,$connection);
  21. confirmQuery($resultset);
  22. while ($row = mysql_fetch_array($resultset)) {
  23. $resid = $row['res_id'];
  24. $resName = $row['restaurant_name'];
  25. $address = $row['address'];
  26. $phone = $row['phone_number'];
  27. $menu = $row['menu_card'];
  28. $costForTwo = $row['cost_for_two'];
  29. $vnv = $row['veg_non_veg'];
  30. $payment = $row['payment_options'];
  31. $buffet = $row['buffet_availability'];
  32. $dineInTa = $row['dinein_take_away'];
  33. $homeDelivery = $row['home_delivery'];
  34. $cuisine = array();
  35. $q2 = "SELECT cuisine_name
  36. FROM cuisines JOIN (SELECT cuisine_id FROM serves WHERE rest_id=$resid) as cid
  37. on cuisines.cuisine_id=cid.cuisine_id";
  38. $res = mysql_query($q2, $connection);
  39. confirmQuery($res);
  40. while($r = mysql_fetch_array($res)){
  41. $cuisine[] = $r['cuisine_name'];
  42. }
  43. $q2 = "SELECT locality_name, city_name
  44. FROM city JOIN (SELECT * FROM located_in WHERE rest_id=$resid) as cityid
  45. on city.city_id=cityid.city_id";
  46. $res = mysql_query($q2, $connection);
  47. confirmQuery($res);
  48. while($r = mysql_fetch_array($res)){
  49. $res_city = $r['city_name'];
  50. $res_loc = $r['locality_name'];
  51. }
  52. $initDat[] = array(
  53. 'resid'=>$resid,
  54. 'resname'=>$resName,
  55. 'rescity'=>$res_city,
  56. 'resloc'=>$res_loc,
  57. 'rescuisine'=>$cuisine,
  58. 'resaddress'=>$address,
  59. 'resphone'=>$phone,
  60. 'resmenu'=>$menu,
  61. 'rescost'=>$costForTwo,
  62. 'resvnv'=>$vnv,
  63. 'respayment'=>$payment,
  64. 'resbuffet'=>$buffet,
  65. 'resdineta'=>$dineInTa,
  66. 'reshomedel'=>$homeDelivery
  67. );
  68. }
  69. var_dump(json_encode(array('searchResult'=>$initDat)));
  70. }
  71. else{
  72. if($location == 'All locations'){
  73. echo 'city + all locs';
  74. $query = "select * from restaurant join
  75. (select rest_id from located_in join
  76. (select city_id from city where city_name='$city') as r1
  77. where r1.city_id=located_in.city_id) as r2
  78. where restaurant.res_id=r2.rest_id";
  79. $resultset = mysql_query($query,$connection);
  80. confirmQuery($resultset);
  81. while ($row = mysql_fetch_array($resultset)) {
  82. $resid = $row['res_id'];
  83. $resName = $row['restaurant_name'];
  84. $address = $row['address'];
  85. $phone = $row['phone_number'];
  86. $menu = $row['menu_card'];
  87. $costForTwo = $row['cost_for_two'];
  88. $vnv = $row['veg_non_veg'];
  89. $payment = $row['payment_options'];
  90. $buffet = $row['buffet_availability'];
  91. $dineInTa = $row['dinein_take_away'];
  92. $homeDelivery = $row['home_delivery'];
  93. $cuisine = array();
  94. $q2 = "SELECT cuisine_name
  95. FROM cuisines JOIN (SELECT cuisine_id FROM serves WHERE rest_id=$resid) as cid
  96. on cuisines.cuisine_id=cid.cuisine_id";
  97. $res = mysql_query($q2, $connection);
  98. confirmQuery($res);
  99. while($r = mysql_fetch_array($res)){
  100. $cuisine[] = $r['cuisine_name'];
  101. }
  102. $q2 = "SELECT locality_name, city_name
  103. FROM city JOIN (SELECT * FROM located_in WHERE rest_id=$resid) as cityid
  104. on city.city_id=cityid.city_id";
  105. $res = mysql_query($q2, $connection);
  106. confirmQuery($res);
  107. while($r = mysql_fetch_array($res)){
  108. $res_city = $r['city_name'];
  109. $res_loc = $r['locality_name'];
  110. }
  111. $initDat[] = array(
  112. 'resid'=>$resid,
  113. 'resname'=>$resName,
  114. 'rescity'=>$res_city,
  115. 'resloc'=>$res_loc,
  116. 'rescuisine'=>$cuisine,
  117. 'resaddress'=>$address,
  118. 'resphone'=>$phone,
  119. 'resmenu'=>$menu,
  120. 'rescost'=>$costForTwo,
  121. 'resvnv'=>$vnv,
  122. 'respayment'=>$payment,
  123. 'resbuffet'=>$buffet,
  124. 'resdineta'=>$dineInTa,
  125. 'reshomedel'=>$homeDelivery
  126. );
  127. }
  128. var_dump(json_encode(array('searchResult'=>$initDat)));
  129. }
  130. else{
  131. echo 'city + particular loc';
  132. }
  133. }
  134. }
  135. else{
  136. }
  137. ?>
  138. <!DOCTYPE html>
  139. <html>
  140. <head>
  141. <title>Khaugali home</title>
  142. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  143. <link rel="stylesheet" href="../css/bootstrap.css" />
  144. <link rel="stylesheet" href="../css/bootstrap-responsive.css" />
  145. <link rel="stylesheet" href="../css/common.css" />
  146. <style>
  147. #content {
  148. /*margin-right: 250px;*/
  149. /*max-width: 70%;*/
  150. overflow-y: scroll;
  151. }
  152. #sidebar {
  153. border-right: 1px solid black;
  154. }
  155. .rightCol {
  156. text-align: right;
  157. }
  158. </style>
  159. </head>
  160. <body>
  161. <div id="header" class="row-fluid">
  162. <a href="home.php"><h2 id="logo" class="span6">KhauGali.com</h2></a>
  163. <?php
  164. include_once 'publicFunction.php';
  165. showAuth();
  166. ?>
  167. </div>
  168. <hr class="head"/>
  169. <div id="content" class="row-fluid">
  170. <div class="span12">
  171. <form style="margin-left:35%;"
  172. action="searchresult.php"
  173. method="get">
  174. <input type="text" style="visibility: hidden; width: 0px" name="location" value="<?php echo $location; ?>" />
  175. <input type="text" style="visibility: hidden; width: 0px" name="city" value="<?php echo $city; ?>" />
  176. <input type="text" name="search_key" id ="search_key" placeholder="Search by restaurant"
  177. class="input-large search-query"/> <input type="submit" value="GO" name="submit" class="btn span1"/>
  178. </form>
  179. </div>
  180. <div class="container-fluid" >
  181. <div class="row-fluid" >
  182. <div class="span2" id="sidebar">
  183. <!--Sidebar content-->
  184. Filters <a href="">Reset All</a>
  185. &nbsp;
  186. <div id="cuisine">
  187. <h5>cuisine</h5>
  188. <label class="checkbox">
  189. <input type="checkbox" value="1"> All
  190. </label>
  191. <label class="checkbox">
  192. <input type="checkbox" value="2"> North Indian
  193. </label>
  194. <label class="checkbox">
  195. <input type="checkbox" value="3"> South Indian
  196. </label>
  197. <label class="checkbox">
  198. <input type="checkbox" value="4"> Gujarati
  199. </label>
  200. <label class="checkbox">
  201. <input type="checkbox" value="5"> Chinese
  202. </label>
  203. <hr />
  204. </div>
  205. <div id="cost">
  206. <h5>Cost For Two</h5>
  207. <label class="checkbox">
  208. <input type="checkbox" value=""> Less than 300
  209. </label>
  210. <label class="checkbox">
  211. <input type="checkbox" value=""> 300-500
  212. </label>
  213. <label class="checkbox">
  214. <input type="checkbox" value=""> 500-1000
  215. </label>
  216. <label class="checkbox">
  217. <input type="checkbox" value=""> 1000-2000
  218. </label>
  219. <label class="checkbox">
  220. <input type="checkbox" value=""> More than 2000
  221. </label>
  222. <hr />
  223. </div>
  224. <div id="veg">
  225. <label class="checkbox">
  226. <input type="checkbox" value=""> Veg
  227. </label>
  228. <label class="checkbox">
  229. <input type="checkbox" value=""> Non-Veg
  230. </label>
  231. <label class="checkbox">
  232. <input type="checkbox" value=""> Egg
  233. </label>
  234. <hr />
  235. </div>
  236. <div id="pay">
  237. <h5>Payment options</h5>
  238. <label class="checkbox">
  239. <input type="checkbox" value=""> Cash
  240. </label>
  241. <label class="checkbox">
  242. <input type="checkbox" value=""> Credit card
  243. </label>
  244. <hr />
  245. </div>
  246. <div id="misc">
  247. <label class="checkbox">
  248. <input type="checkbox" value=""> Buffet
  249. </label>
  250. <label class="checkbox">
  251. <input type="checkbox" value=""> Take-away
  252. </label>
  253. <label class="checkbox">
  254. <input type="checkbox" value=""> Home delivery
  255. </label>
  256. </div>
  257. <a href="">Reset All</a>
  258. </div>
  259. <div class="span10" id="searchres">
  260. <!--Body content-->
  261. <h3 class="form-signin-heading">
  262. <?php
  263. if($city == 'All cities'){
  264. echo 'All restaurants';
  265. }
  266. else{
  267. if($location == 'All locations'){
  268. echo 'All restaurants in '. $city;
  269. }
  270. else{
  271. echo 'All restaurants in '. $location . ' '. $city;
  272. }
  273. }
  274. ?>
  275. </h3>
  276. <div class="btn-group" data-toggle="buttons-radio">
  277. <button type="button" class="btn btn-primary">Dine In</button>
  278. <button type="button" class="btn btn-primary">Take Away</button>
  279. <button type="button" class="btn btn-primary">All</button>
  280. </div>
  281. <div class="pull-right">
  282. Sorted by:
  283. <div class="btn-group" data-toggle="buttons-radio">
  284. <button type="button" class="btn btn-primary">Rating</button>
  285. <button type="button" class="btn btn-primary">Cost</button>
  286. </div>
  287. </div>
  288. <table class="table" id="search-content">
  289. <!-- <tr>
  290. <td>
  291. <h5>Restaurant 1</h5>
  292. <p>Locality:</p>
  293. <p>Cuisines available: </p>
  294. <p>Address: </p>
  295. <p>Contact number: </p>
  296. </td>
  297. <td class="rightCol">
  298. <div class="rating">
  299. <i class="icon-star"></i>
  300. <i class="icon-star"></i>
  301. <i class="icon-star"></i>
  302. <i class="icon-star-empty"></i>
  303. <i class="icon-star-empty"></i>
  304. </div>
  305. &nbsp;
  306. <p>Cost for two: </p>
  307. <ul>
  308. <li><a href="">Menu card</a></li>
  309. <li><a href="">Card</a></li>
  310. <li><a href="">Home Delivery</a></li>
  311. </ul>
  312. </td>
  313. </tr>
  314. <tr>
  315. <td>
  316. <h5>Restaurant 2</h5>
  317. <p>Locality:</p>
  318. <p>Cuisines available: </p>
  319. <p>Address: </p>
  320. <p>Contact number: </p>
  321. </td>
  322. <td class="rightCol">
  323. <div class="rating">
  324. <i class="icon-star"></i>
  325. <i class="icon-star"></i>
  326. <i class="icon-star"></i>
  327. <i class="icon-star-empty"></i>
  328. <i class="icon-star-empty"></i>
  329. </div>
  330. &nbsp;
  331. <p>Cost for two: </p>
  332. <ul>
  333. <li><a href="">Menu card</a></li>
  334. <li><a href="">Card</a></li>
  335. <li><a href="">Home Delivery</a></li>
  336. </ul>
  337. </td>
  338. </tr>
  339. <tr>
  340. <td>
  341. <h5>Restaurant 3</h5>
  342. <p>Locality:</p>
  343. <p>Cuisines available: </p>
  344. <p>Address: </p>
  345. <p>Contact number: </p>
  346. </td>
  347. <td class="rightCol">
  348. <div class="rating">
  349. <i class="icon-star"></i>
  350. <i class="icon-star"></i>
  351. <i class="icon-star"></i>
  352. <i class="icon-star-empty"></i>
  353. <i class="icon-star-empty"></i>
  354. </div>
  355. &nbsp;
  356. <p>Cost for two: </p>
  357. <ul>
  358. <li><a href="">Menu card</a></li>
  359. <li><a href="">Card</a></li>
  360. <li><a href="">Home Delivery</a></li>
  361. </ul>
  362. </td>
  363. </tr>-->
  364. </table>
  365. </div>
  366. </div>
  367. </div>
  368. </div>
  369. <hr class="foot" />
  370. <div id="footer" class="row-fluid">
  371. <div class="span8" id="links">
  372. <a href="">Home</a> &VerticalBar;
  373. <a href="">About Khaugali.com</a> &VerticalBar;
  374. <a href="">Suggest a Restaurant</a> &VerticalBar;
  375. <a href="">Contact us</a> &VerticalBar;
  376. <a href="">Privacy</a> &VerticalBar;
  377. <a href="">Site map</a>
  378. </div>
  379. <div class="span4" id="company">
  380. <p class="pull-right">&copy; MAD productions</p>
  381. </div>
  382. </div>
  383. <script src="../js/jquery-1.9.1.js"></script>
  384. <script src="../js/bootstrap.js"></script>
  385. <script src="../js/jqBootstrapValidation.js"></script>
  386. <script>
  387. var initDat = <?php echo json_encode(array('searchResult'=>$initDat)); ?>;
  388. $('document').ready(function(){
  389. var dat = initDat;
  390. //dat = jQuery.parseJSON(dat);
  391. dat = JSON.parse(dat);
  392. var htm = '';
  393. for(var i=0; i< dat.searchResult.length; i++){
  394. htm = htm + '<tr>';
  395. htm = htm + '<td>hello</td>';
  396. htm = htm + '</tr>';
  397. }
  398. $('#search-content').html(htm);
  399. });
  400. </script>
  401. </body>
  402. </html>
  403. <?php
  404. connectionClose($connection);