473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Query for Search Page using drop down

hi,
This is my the search code i have tried it works well with the fiels stores as string in the database. But i have stored the qualification and specialization as int in database. Each selected value has a unique id. I am not able to search by qualification and specialization fields. If i enter the qualification name in text box then it never displays anything. How can i do it for values stored as int in the table.

Expand|Select|Wrap|Line Numbers
  1. <html> 
  2. <head> 
  3. </head> 
  4. <body> 
  5. <?php 
  6. $error="";
  7. if (!isset($_POST['Submit'])) { 
  8. // form not submitted 
  9. ?> 
  10.  
  11. <form action="<?=$_SERVER['php_SELF']?>" method="post"> 
  12. search <input type="text" name="search"><br> 
  13. <select size="1" name="dropdown"> 
  14. <option value="" selected>search By...</option> 
  15. <option value="YearsExp">Experience</option> 
  16. <option value="FunctionalArea">Functional Area</option> 
  17. <option value="Qualification">Qualification</option> 
  18. <option value="Specialization">Specialization</option> 
  19. <option value="KeySkills">Key Skills</option> 
  20. <option value="Institute">Institute</option> 
  21. </select> 
  22. <input type="Submit" value="Submit" name="Submit">  
  23. </form> 
  24.  
  25. <?php 
  26.  
  27. else { 
  28.  
  29. // form submitted 
  30. // set server access variables 
  31. $host = "localhost"; 
  32. $user = "root"; 
  33. $pass = "database"; 
  34. $db = "skills_portfolio"; 
  35.  
  36. $search = empty($_POST['search'])? die ($error= "Enter search Criteria") : mysql_escape_string($_POST['search']); 
  37. $dropdown = empty($_POST['dropdown'])? die ($error= "Select from dropdown") : mysql_escape_string($_POST['dropdown']); 
  38.  
  39. // Open Connection 
  40.  
  41. $connect = mysql_connect($host, $user, $pass) or die ("Unable to connect to host"); 
  42.  
  43. //Select Database 
  44.  
  45. mysql_select_db($db) or die ("Unable to connect to database"); 
  46.  
  47. //Create Query 
  48.  
  49. $query = "SELECT * FROM userdetails WHERE $dropdown='$search'" or die (mysql_error()); 
  50. $data = mysql_query($query) or die(mysql_error()); 
  51.  
  52. echo "<b><center>Database Output</center></b><br><br>"; 
  53.  
  54. while($info=mysql_fetch_array($data)){
  55. //Print it out to page 
  56. echo "".$info['UserName'] . " <BR>"; 
  57.  
  58. }// end of while
  59.  
  60. mysql_close($connect);  
  61. ?> 
  62. </body> 
  63. </html> 
  64.  
Mar 12 '08 #1
5 3685
Plz can anyone help me. plz
Mar 12 '08 #2
TheServant
1,168 Expert 1GB
But i have stored the qualification and specialization as int in database.
So do you mean qualification and specialization is a number in the database? Have you tried to search for a number? Does that work?
Mar 12 '08 #3
ronverdonk
4,258 Expert 4TB
If you want to search by an id you must define that id number in the drop down, e.g. when Fnctional area has id 42, you specify it as[php]<option value=42>Functional Area</option>[/php]Then, after submit, the number 42 is passed to your POST array.

Ronald
Mar 12 '08 #4
If you want to search by an id you must define that id number in the drop down, e.g. when Fnctional area has id 42, you specify it as[php]<option value=42>Functional Area</option>[/php]Then, after submit, the number 42 is passed to your POST array.

Ronald
If i enter the id in text box the search goes well. For eg. in my drop down i ve qualification as a criteria for search. If user selects qualification in dropdown then he will enter say B.E. in text box and not the id coresponding to B.E. So the users with B.E. as their qualification should be displayed. My problem is in the database in usersdetails it is stored as id and not as B.E.
Should if loop be used?
Mar 13 '08 #5
ronverdonk
4,258 Expert 4TB
You either use a drop down list with the correct numeric values (ID) in the value field and the description in the text field OR you allow the user to enter some free format text in a text field which you have to translate into an ID field.

For the former, I gave you an example which you have to apply to all such drop downs. For the latter you will have to develop some algorithm yourself. When you don't know how to implement the given example in your code, I suggest you fiorst take a course in HTML to learn how to code a drop down liast and how to pass to and extract parameters from the POST array.

Ronald
Mar 14 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rudy | last post by:
Hello! I have 4 diffrent drop downlist. I want a user to select a value from a drop down list, and place it in a SELECT statement. How would I put that value in the select statement. And if the...
1
by: accyboy1981 | last post by:
Hi, I new to C# so please forgive me if this is simple. I've got 2 drop down lists the first is hard coded with data where as the second is populated from a database. The options that appear in...
2
by: Paul Revere | last post by:
Hi, all of you! I am new to this community. I am a web designer and a friend of mine and I have a server and manage websites (mostly ours but also a few clients). I manage the sites and he does...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
6
by: nbomike | last post by:
I am trying to integrate a custom page into a shopping cart app written in PHP. The custom page is basically a part finder widget that helps customers find a car part based on the car's make, model,...
1
by: bobby44 | last post by:
Hi, I hope someone can help with a query I'm stuck on. I think it will involve inner join but I can't get my head around it. I have two tables that relate to venues fr weddings: --...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
0
by: tkip | last post by:
Gents.. I am just looking for ideas as to how to approach the query of DB I am working on. Basically, it's a database of welding procedures and depending on the metal you choose, appropriate...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.