www.webdeveloper.com
Results 1 to 3 of 3

Thread: Use Different Radio Buttons for Different Queries

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Use Different Radio Buttons for Different Queries

    I am new to php and need some help. I have a MySQL db that I would like to use radio buttons for the user to submit 4 different querries to display information. I am having trouble getting the POST method to translate to a variable that I can assign to a query statement.

  2. #2
    Join Date
    Oct 2009
    Location
    Michigan
    Posts
    19
    On the markup side of things, make sure all your radio buttons have the same name. So it might look like this:

    Code:
    <input type="radio" name="choices" value="1" /> Run Query 1
    <input type="radio" name="choices" value="2" /> Run Query 2
    <input type="radio" name="choices" value="3" /> Run Query 3
    Then in the script that processes the post data, one way might be to store the queries in an array and use the $_POST["choices"] variable to choose the right one:

    Code:
    <?
    $queries[0] = "SELECT * FROM blah";
    $queries[1] = "SELECT id FROM table";
    $queries[2] = "SELECT something FROM blah";
    
    $query = $queries[$_POST["choices"] - 1]; // subtract 1 since arrays start at 0
    $result = mysql_query($query);
    Something like that.

    (Of course, especially when dealing with user data and your database, you should flesh that code out a lot more to add checks to make sure they POST data is an integer and within the range of your array and all that junk. But that sample should get you started. Let me know if you need anything cleared up!)
    Last edited by weenis; 10-28-2009 at 08:58 PM.

  3. #3
    Join Date
    Oct 2009
    Posts
    2

    Thanks

    I'll give it a try, I can run the queries but couldn't make the association to the radio button.

    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles