943,186 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 652
  • PHP RSS
Jul 6th, 2010
0

PHP Database comparisson

Expand Post »
Hey guys, currently I am writing a script that will allow users to use a html drop down menu to select regions of the world (based on entry in a js file). We need the results to be compared against a database and return another answer without the user using any submit button.

So basically lets say it was a locator script for snacks. The user wanted to select "Chocolate Cookie" well on the drop down menu they would select "snack" then on the next field that actively changes they would select "cookie" then "chocolate" the script would then check the databases for snacks that fall into those categories and display "Chocolate cookie" and "chocolate chip cookie" however if the user only selects "cookie" then "chocolate chip cookie" "chocolate cookie" "ginger snap" and "oreo" should all display etc.

The code I am working with:
PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Region > Country > Division</title>
  4. <style type="text/css">
  5.  
  6. body {
  7. background: #fff;
  8. }
  9. #widget {
  10. width: 780px;
  11. height: 480px;
  12. font: normal 10px verdana;
  13. text-align: center;
  14. margin: 40px auto;
  15. border: 5px #aaa;
  16. border-style: outset inset inset outset;
  17. background: url();
  18. }
  19. form {
  20. width: 98%;
  21. margin: 200px 0 60px 0;
  22. }
  23. select {
  24. width: 190px;
  25. font: normal 11px verdana;
  26. color: #000;
  27. background: #fff;
  28. }
  29. #txtregion {
  30. width: 98%;
  31. height: 16px;
  32. font: normal 12px verdana;
  33. letter-spacing: .4em;
  34. margin: auto;
  35. border-bottom: 1px black solid;
  36. }
  37. #txtplacename {
  38. width: 98%;
  39. height: 16px;
  40. font: normal 10px verdana;
  41. margin: auto;
  42. }
  43.  
  44. </style>
  45. <script type="text/javascript" src="city_state.js"></script>
  46. </head>
  47. <body>
  48. <div id="widget">
  49. <form>
  50. Region&raquo; <select onchange="set_country(this,country,city_state)" size="1" name="region">
  51. <option value="" selected="selected">SELECT REGION</option>
  52. <option value=""></option>
  53. <script type="text/javascript">
  54. setRegions(this);
  55. </script>
  56. </select>
  57. Country&raquo; <select name="country" size="1" disabled="disabled" onchange="set_city_state(this,city_state)"></select>
  58. City/State&raquo; <select name="city_state" size="1" disabled="disabled" onchange="print_city_state(country,this)"></select>
  59. </form>
  60. <div id="txtregion"></div>
  61. <div id="txtplacename"></div>
  62. </div>
  63. <script>
  64. <?php
  65.  
  66. // Get the search variable from URL
  67.  
  68. $var = @$_GET[''] ;
  69. $trimmed = trim($var); //trim whitespace from the stored variable
  70.  
  71. // rows to return
  72. $limit=10;
  73.  
  74. // check for an empty string and display a message.
  75. if ($trimmed == "")
  76. {
  77. echo "<p>Please enter a search...</p>";
  78. exit;
  79. }
  80.  
  81. // check for a search parameter
  82. if (!isset($var))
  83. {
  84. echo "<p>We dont seem to have a search parameter!</p>";
  85. exit;
  86. }
  87.  
  88. //connect to your database
  89. mysql_connect("localhost","username","password"); //(host, username, password)
  90.  
  91. //specify database
  92. mysql_select_db("database") or die("Unable to select database"); //select which database we're using
  93.  
  94. // Build SQL Query
  95. $query = "select * from the_table where 1st_field like \"%$trimmed%\"
  96. order by 1st_field"; // specify table and field names for the SQL query
  97.  
  98. $numresults=mysql_query($query);
  99. $numrows=mysql_num_rows($numresults);
  100.  
  101. ?>
  102. </script>
  103. </body>
  104. </html>

Please bare in mind my experience in PHP is limited most of this code was made by a developer that I am no longer in contact with so I will need things in laments terms - thanks in advanced for your help guys.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Member 784854 is offline Offline
1 posts
since Jul 2010
Jul 6th, 2010
0
Re: PHP Database comparisson
You need AJAX TO Perform this work.
Reputation Points: 8
Solved Threads: 4
Banned
keval_hack is offline Offline
66 posts
since Jan 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: Sqlite syntax
Next Thread in PHP Forum Timeline: Help About Ion Cube......





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


Follow us on Twitter


© 2011 DaniWeb® LLC