[HELP] Regarding on select Box

Reply

Join Date: Nov 2008
Posts: 2
Reputation: syazuchan is an unknown quantity at this point 
Solved Threads: 0
syazuchan syazuchan is offline Offline
Newbie Poster

[HELP] Regarding on select Box

 
0
  #1
Nov 18th, 2008
I want to build a simple search system.
I have this one page call search.php which I had a multiple select box that i retrieve from the database..

some of the code are like this:
  1. <form method="post" action="modulartabulated.php">
  2. <table width="75%" border="0" align="center">
  3. <tr>
  4. <td>Date:</td>
  5. <td><input type="text" name="date" /></td>
  6. </tr>
  7. <tr>
  8. <td>Examiner:</td>
  9. <td><input type="text" name="examiner" /> </td>
  10. </tr>
  11. <tr>
  12. <td>Program:</td>
  13. <td><select name="program" id="prog">
  14. <?
  15. $db=mysql_connect($hostname,$username,$password);
  16. mysql_select_db($dbname,$db);
  17.  
  18. $query = "SELECT * from execdipprog";
  19. $record = mysql_query($query);
  20. $numrows = mysql_num_rows($record);
  21.  
  22. if($numrows > 0 )
  23. {
  24. while($row = mysql_fetch_array($record))
  25. {
  26. $prog_id = $row['K_Name'];
  27. $prog_name = $row['K_Desc'];
  28. echo("<option value='$prog_name'>".$prog_name."</option>");
  29. }
  30. }
  31. ?>
  32. </select></td>
  33. </tr>
  34. <tr>
  35. <td>Class</td>
  36. <td><select name="class" id="kelas">
  37. <?
  38. $db=mysql_connect($hostname,$username,$password);
  39. mysql_select_db($dbname,$db);
  40.  
  41. $query = "SELECT * from execdipclass";
  42. $record = mysql_query($query);
  43. $numrows = mysql_num_rows($record);
  44.  
  45. if($numrows > 0)
  46. {
  47. while($row = mysql_fetch_array($record))
  48. {
  49. $class_id = $row['C_Id'];
  50. $class_name = $row['C_Name'];
  51. echo("<option value='$class_name'>".$class_name."</option>");
  52. }
  53. }
  54. ?>
  55. </select></td>
  56. </tr>
  57. <tr>
  58. <td>Module:</td>
  59. <td><select name="subject" id="subjek">
  60. <?
  61. $db=mysql_connect($hostname,$username,$password);
  62. mysql_select_db($dbname,$db);
  63.  
  64. $query = "SELECT * from modul";
  65. $record = mysql_query($query);
  66. $numrows = mysql_num_rows($record);
  67.  
  68. if($numrows>0)
  69. {
  70. while($row = mysql_fetch_array($record))
  71. {
  72. $sub_id = $row['M_ID'];
  73. $sub_name = $row['M_Desc'];
  74. echo("<option value='$sub_name'>".$sub_id."</option>");
  75. }
  76. }
  77. ?>
  78. </select></td>
  79. </tr>
  80. <tr>
  81. <td colspan="2"><div align="center">
  82. <input type="submit" name="generate" value="Display" />
  83. </div></td>
  84. </tr>
  85.  
  86. </table>
  87. </form>

On the next page..I want to retrieve data from database according to the selected data from search.php. Can anyone tell me how to code it? I've use the regular POST method but it didn't work

Please Help
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: [HELP] Regarding on select Box

 
0
  #2
Nov 18th, 2008
why not to store your search results on sessions....
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 14
Reputation: jack239 is an unknown quantity at this point 
Solved Threads: 1
jack239's Avatar
jack239 jack239 is offline Offline
Newbie Poster

Re: [HELP] Regarding on select Box

 
0
  #3
Nov 18th, 2008
You can grab the values from the global $_REQUEST array or $_POST array. The selected values are avaialble in the variable which has the same name as the form tag. e.g. the selected value for subject can be retrieved as $_REQUEST['subject']
Stuck in the middle of Java/PHP/Ajax development?

For free help on any technology and free articles visit http://www.techcubetalk.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: [HELP] Regarding on select Box

 
0
  #4
Nov 19th, 2008
use the $_POST data to do it. not $_REQUEST, in which is not very secure.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: syazuchan is an unknown quantity at this point 
Solved Threads: 0
syazuchan syazuchan is offline Offline
Newbie Poster

Re: [HELP] Regarding on select Box

 
0
  #5
Jan 4th, 2009
thank you for all the reply.
however i ad somethign else to my code.
I add onChange statement at the dropdown menu.

so code become like this,

<form name="modulartabulate" method="post" action="modulartabulated.php">
  <table width="75%" border="0" align="center">
    <tr>
      <td>Date:</td>
      <td><input type="text" name="date" /></td>
    </tr>
    <tr>
      <td>Examiner:</td>
      <td><input type="text" name="examiner"  />      </td>
    </tr>
    <tr>
      <td>Program:</td>
      <td><select oncahnge="modulartabulted.submit()" name="program" id="prog">
        <?
			$db=mysql_connect($hostname,$username,$password);
			mysql_select_db($dbname,$db);
			
			$query = "SELECT * from execdipprog";
			$record = mysql_query($query);
			$numrows = mysql_num_rows($record);
			
			if($numrows > 0 )
			{
				while($row = mysql_fetch_array($record))
				{
					$prog_id = $row['K_Name'];
					$prog_name = $row['K_Desc'];
					echo("<option value='$prog_name'>".$prog_name."</option>");
				}
			}
		?>
      </select></td>
    </tr>
    <tr>
      <td>Class</td>
      <td><select modulartabulted.submit() name="class" id="kelas">
          <?
			$db=mysql_connect($hostname,$username,$password);
			mysql_select_db($dbname,$db);
			
			$query = "SELECT * from execdipclass where K_Name='program'";
			$record = mysql_query($query);
			$numrows = mysql_num_rows($record);
			
			if($numrows > 0)
			{
				while($row = mysql_fetch_array($record))
				{
					$class_id = $row['C_Id'];
					$class_name = $row['C_Name'];
					echo("<option value='$class_name'>".$class_name."</option>");
				}
			}
		?>
        </select></td>



My problem is, I want the 2nd select option (drop down menu) to list the data from database according to the 1st select option (drop down menu). Using the coding above, after I selected the 1st select option (drop down menu), it redirect to the "modulartabulted.php" which suppose to happend after I click the submit button after I finish select from all the drop down list menu.



to clear it all out I'll show from example

according to the image that i've attach, i want to list out data from the database. Here a the step by step.
1. First I select Program (A)
2. Then Class (B) will list its data according to Program (A)
3. After I select Class (B), Student Name (C) will list it data according to the Class (B) that I choose.
4. Module (D) will list its data according to the Program (A) that I choose earlier.
5. After finish selecting, I click display button and it will be directed to "modulartabulated.php" page where all the date been sort according to the data I selected in previous page.

All of above happen to be in the same form.

Please help.
Thank you in advanced.
Last edited by syazuchan; Jan 4th, 2009 at 10:20 pm.
Attached Thumbnails
serach1wt8.jpg  
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