How to combine a list of choices to determine which select statement

Posted by Larry on Stack Overflow See other posts from Stack Overflow or by Larry
Published on 2012-11-14T22:50:01Z Indexed on 2012/11/14 23:00 UTC
Read the original article Hit count: 237

Filed under:
|
|
|

I have a mysql db and am using php 5.2

What I am trying to do is offer a list of options for a person to select (only 1). The chosen option will cause a select, update, or delete statement to be ran.

The results of the statement do not need to be shown, although, showing the old and then the new would be nice (no problems with that part tho'.).

Pseudo-Code:

Assign $choice = 0
Check the value of $choice  //  This way, if it = 100, we do a break
Select a Choice:<br>
  1.  Adjust Status Value (+60) // $choice = 1<br>
  2.  Show all Ships <br> // $choice = 2
  3.  Show Ships in Port <br> // $choice = 3
  ...  
  0.  $choice="100"  // if the value =100, quit this part

Use either case (switch) or if/else statements to run the users choice1

If the choice is 1, then run the "Select" statement with the variable of $sql1
    --  "SELECT ....
If the choice is 2, then run the "Select" statement with the variable of $sql2
    --- SELECT * FROM Ships
If the choice is 3, then run the "Select" statement with the variable of $sql3  <br>
    ....
If the choice is 0, then we are done.

I figured the (3) statements would be assigned in php as:

$sql1="...".
$sql2="SELECT * FROM Ships"
$sql3="SELECT * FROM Ships WHERE nPort="1"

My idea was to use the switch statement, but got lost on it. :(

I would like the options to be available over and over again, until a variable ($choice) is selected. In which case, this particular page is done and goes back to the "Main Menu"?

The coding and display, if I use it, I can do. Just not sure how to write the way to select which one I want. It is possible that I would run all of the queries, and other times, only one, so that is why I would like the choice. An area I get confused in is the proper forms to use such as -- ' ' " " and ...??

Not sure the # of options I will end up with, but it will be more than 5 but less than 20 / page. So if I get the system down for 2-3 choices, I can replicate it for as many as I may need. And, as always, if a better way exists, I am willing to try it.

Thanks again...

Larry

© Stack Overflow or respective owner

Related posts about php

Related posts about sql