Select Menu Declaration in PHP

Thread Solved

Join Date: Nov 2009
Posts: 40
Reputation: levsha is an unknown quantity at this point 
Solved Threads: 0
levsha levsha is offline Offline
Light Poster

Select Menu Declaration in PHP

 
0
  #1
Nov 3rd, 2009
How do you declare your select menu in the PHP?
Does it have to be an array of variables? One single variable?
Something else?
Let's say this one:

  1. <select name="search" title="Search Criteria">
  2. <option value="id">ID Status</option>
  3. <option value="ip">IP Status</option>
  4. <option value="pd">PD Status</option>
  5. <option value="nva">NVA Status</option>
  6. </select>

Thank you!
Last edited by levsha; Nov 3rd, 2009 at 12:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 607
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 70
network18 network18 is offline Offline
Practically a Master Poster
 
0
  #2
Nov 4th, 2009
First of what you gave got nothing to do with PHP, its a HTML select element. and what do you mean by declare.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 40
Reputation: levsha is an unknown quantity at this point 
Solved Threads: 0
levsha levsha is offline Offline
Light Poster
 
0
  #3
Nov 4th, 2009
Originally Posted by network18 View Post
First of what you gave got nothing to do with PHP, its a HTML select element. and what do you mean by declare.
Yes, I know.
What I mean is I need to write an IF... ELSE statement in PHP using data from the select menu that comes from my HTML form.
Can't figure out how this should be done.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 607
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 70
network18 network18 is offline Offline
Practically a Master Poster
 
0
  #4
Nov 4th, 2009
Originally Posted by levsha View Post
Yes, I know.
What I mean is I need to write an IF... ELSE statement in PHP using data from the select menu that comes from my HTML form.
Can't figure out how this should be done.
Still you not describing, what exactly you expect from the PHP, even though this is a proper English than your first post.
I assume you have some html form and in another page you putting those inputs in the select ekement.
For example in your first html form you ask the user to input his qualification etc.He enters Xth,XIIth, Grad and Post-grad details and then next form carries the data and displayed in the select element.
If I am wrong correct me.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 15
Reputation: violarisgeorge is an unknown quantity at this point 
Solved Threads: 3
violarisgeorge's Avatar
violarisgeorge violarisgeorge is offline Offline
Newbie Poster
 
0
  #5
Nov 4th, 2009
Simply, if I understand what you want to do, you should have a value for each option in your HTML select element of your form. Then, in php, you should have variables which grab those option values (with $_POST or $_GET depending on your form), and then feed them into a switch statement (better than IF statement for this purpose I believe) and put inside each case of your switch what you want it to do for each option.

i.e. each case represents one of the options.
I take your reality and substitute my own
violarisgeorge.com
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 40
Reputation: levsha is an unknown quantity at this point 
Solved Threads: 0
levsha levsha is offline Offline
Light Poster
 
0
  #6
Nov 5th, 2009
Originally Posted by violarisgeorge View Post
Simply, if I understand what you want to do, you should have a value for each option in your HTML select element of your form. Then, in php, you should have variables which grab those option values (with $_POST or $_GET depending on your form), and then feed them into a switch statement (better than IF statement for this purpose I believe) and put inside each case of your switch what you want it to do for each option.

i.e. each case represents one of the options.
Let's say I have this in my HTML form:
  1. <select name="search" title="Search Criteria">
  2. <option value="id">ID Status</option>
  3. <option value="ip">IP Status</option>
  4. <option value="pd">PD Status</option>
  5. </select>

Here is my PHP:
  1. <?php
  2.  
  3. $search = @$_POST['search'];
  4. $id = @$_POST['id'];
  5. $ip = @$_POST['ip'];
  6. $pd = @$_POST['pd'];
  7.  
  8. ?>

Is that correct?
What if I need to grab a value from my HTML select element (one of the options) and send it to a database?
What do I write in my INSERT statement?

$sql = "insert into mytable (status) values ('$_POST[???]')";
Last edited by Ezzaral; Nov 5th, 2009 at 5:40 pm. Reason: Added code tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 15
Reputation: violarisgeorge is an unknown quantity at this point 
Solved Threads: 3
violarisgeorge's Avatar
violarisgeorge violarisgeorge is offline Offline
Newbie Poster
 
0
  #7
Nov 5th, 2009
Originally Posted by levsha View Post
Let's say I have this in my HTML form:
  1. <select name="search" title="Search Criteria">
  2. <option value="id">ID Status</option>
  3. <option value="ip">IP Status</option>
  4. <option value="pd">PD Status</option>
  5. </select>

Here is my PHP:
  1. <?php
  2.  
  3. $search = @$_POST['search'];
  4. $id = @$_POST['id'];
  5. $ip = @$_POST['ip'];
  6. $pd = @$_POST['pd'];
  7.  
  8. ?>

Is that correct?
What if I need to grab a value from my HTML select element (one of the options) and send it to a database?
What do I write in my INSERT statement?

$sql = "insert into mytable (status) values ('$_POST[???]')";
No this is not correct. You only need $search = @$_POST['search']; in order to capture the selection. Then in your switch statement you should say that if the $search is equal to id, then do this, and so on.

Then, in your db query you should command something like

  1. $sql = "INSERT INTO `mytable` (status) VALUES ($search);"

IMPORTANT NOTE: The SQL query should go into EVERY single on of your case statements of the switch. I hope you get what I mean... Try it out and report back any problems.
I take your reality and substitute my own
violarisgeorge.com
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 40
Reputation: levsha is an unknown quantity at this point 
Solved Threads: 0
levsha levsha is offline Offline
Light Poster
 
0
  #8
Nov 8th, 2009
Originally Posted by violarisgeorge View Post
No this is not correct. You only need $search = @$_POST['search']; in order to capture the selection. Then in your switch statement you should say that if the $search is equal to id, then do this, and so on.

Then, in your db query you should command something like

  1. $sql = "INSERT INTO `mytable` (status) VALUES ($search);"

IMPORTANT NOTE: The SQL query should go into EVERY single on of your case statements of the switch. I hope you get what I mean... Try it out and report back any problems.

Thank you so, so, so much!
It works perfectly well!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 15
Reputation: violarisgeorge is an unknown quantity at this point 
Solved Threads: 3
violarisgeorge's Avatar
violarisgeorge violarisgeorge is offline Offline
Newbie Poster
 
0
  #9
Nov 8th, 2009
Originally Posted by levsha View Post
Thank you so, so, so much!
It works perfectly well!
I am glad I could help! You should mark this thread solved so others can benefit from it.
I take your reality and substitute my own
violarisgeorge.com
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 610 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC