search from database

Reply

Join Date: Aug 2008
Posts: 149
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster

search from database

 
0
  #1
Dec 1st, 2008
hi frnds,
i am doing a project related to food items..
here i took different categories like restaurants,pubs,foodfestivals,hangouts...
and also i took diffrent tables for each category in database..
each table having area,rname...now i need to search what ever user typed in textbox(area,rname) from database.
plz give any suggestions asap..
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,449
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: search from database

 
0
  #2
Dec 1st, 2008
This is only from the top of my head but if what you place in those 2 fields (area, rname) need to match percisely what are in those 2 columns within the mysql database then you could use something along the following:
  1. <?
  2. //mysql connections
  3. if (isset($_POST['area']) && isset($_POST['rname']))
  4. {
  5. $result=mysql_query("SELECT * FROM `table` WHERE `area`='".$_POST['area']."' AND `rname`='".$_POST['rname']."'");
  6. echo "<table border=1 cellpadding=4 cellspacing=0><tr><td>area</td><td>rname</td><td>column3</td></tr>";
  7. while ($rowid=mysql_fetch_array($result))
  8. {
  9. //perform actions for earch row found
  10. echo "<tr><td>".$rowid['area']."</td>";
  11. echo "<td>".$rowid['rname']."</td>";
  12. echo "<td>".$rowid['column3']."</td></tr>";
  13. }
  14. echo "</table>";
  15. }
  16. ?>
  17.  
  18. <form method='post'>
  19. area=<input type='text' name='area'><br>
  20. rname=<input type='text' name='rname'><br>
  21. <input type='submit' value='submit'>
  22. </form>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: search from database

 
0
  #3
Dec 3rd, 2008
Hi...
What i suggest you is to create a category select box and its value should be the same as of your tablename.... (this is what you have done.. table for every category)

I hope too many php tags doesn't confuses you... Its just to display result in a better way...


  1. <?php
  2.  
  3. if(isset($_POST['submit']))
  4. {
  5.  
  6. $sql="Select * from ".$_POST['category']." where area like '%".$_POST['area']."%' and rname like '%".$_POST['rname']."%' order by area asc";
  7. $result = mysql_query($sql);
  8.  
  9. ?>
  10. <table border="1">
  11. <tr>
  12. <td colspan="2"> Search in table >> <?php echo $_POST['category']; ?></td>
  13. </tr>
  14.  
  15. <?php
  16. if(mysql_num_rows($query) > 0)
  17. {
  18. while($row = mysql_fetch_array($result))
  19. {
  20. ?>
  21. <tr>
  22. <td>$row['area'];</td>
  23. <td>$row['rname'];</td>
  24. </tr>
  25. <?php
  26.  
  27. }
  28. }
  29. else
  30. {
  31. ?>
  32. <tr>
  33. <td colspan="2">No entry found</td>
  34. </tr>
  35. <?php
  36.  
  37. }
  38. ?>
  39.  
  40. </table>
  41. <?php
  42. }
  43.  
  44. ?>
  45.  
  46.  
  47.  
  48. <form name="form_search" method="post" action="">
  49. Select Category <select name="category">
  50. <option value="restaurants">Restaurants</option>
  51. <option value="restaurants">Restaurants</option>
  52. <option value="restaurants">Restaurants</option>
  53. <option value="restaurants">Restaurants</option>
  54. </select>
  55. <br/>
  56. Area <input type="text" name="area" id="area" />
  57. <br />
  58. Rname <input type="text" name="rname" id-"rname" />
  59. <br />
  60. <input type="submit" value="search" name="submit">
  61. </form>
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC