943,549 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1851
  • PHP RSS
Nov 18th, 2008
0

[HELP] Regarding on select Box

Expand Post »
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:
PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
syazuchan is offline Offline
2 posts
since Nov 2008
Nov 18th, 2008
0

Re: [HELP] Regarding on select Box

why not to store your search results on sessions....
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Nov 18th, 2008
0

Re: [HELP] Regarding on select Box

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']
Reputation Points: 13
Solved Threads: 1
Newbie Poster
jack239 is offline Offline
14 posts
since Aug 2008
Nov 19th, 2008
0

Re: [HELP] Regarding on select Box

use the $_POST data to do it. not $_REQUEST, in which is not very secure.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Jan 4th, 2009
0

Re: [HELP] Regarding on select Box

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.
Attached Thumbnails
Click image for larger version

Name:	serach1wt8.jpg
Views:	153
Size:	28.5 KB
ID:	8765  
Last edited by syazuchan; Jan 4th, 2009 at 10:20 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
syazuchan is offline Offline
2 posts
since Nov 2008

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: Multilanguage with PHP-MySQL
Next Thread in PHP Forum Timeline: what is php stands for





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


Follow us on Twitter


© 2011 DaniWeb® LLC