Changing The User's Search Method - PHP/MySQL


Results 1 to 11 of 11

Thread: Changing The User's Search Method - PHP/MySQL

  1. #1
    Join Date
    Feb 2001
    Location
    Midwest U.S.A.
    Posts
    724

    Changing The User's Search Method - PHP/MySQL

    I have a working database search scenario like this:

    * User chooses an item from a drop-down menu, AND...
    * User then types a four digit number into a text field and clicks a "Search" button.

    I've been tasked to change this search method as follows:

    * User chooses an item from (the same) drop-down menu, AND...
    * User clicks a button representing the desired four digit number, which initiates the search.

    There's currently one HTML document, and one PHP script controlling this search. I've isolated the HTML code that controls the text entry field, and the "search" button, but I need to find a way to combine those functions into the one button that sends the search. There's a matrix of 160+ four digit numbers, so I will be building a table of buttons for those numbers (I've already been testing this with a couple of rows of buttons, just to make sure that part of it works). I'm a total noob with PHP, just watched videos to get somewhat up to speed. I do know HTML/CSS and Javascript. Any help with this is very much appreciated, please let me know if more info is needed. Thanks.
    solo~ST

  2. #2
    Join Date
    May 2002
    Posts
    1,254
    Hopefully the four digit numbers are a sequence whereby you can easily embed a php for loop. Otherwise you can read the numbers from a table. php is very similar to c.

  3. #3
    Join Date
    Feb 2001
    Location
    Midwest U.S.A.
    Posts
    724
    Perhaps I can clarify a bit further... After the user selects a choice from the drop-down, they consult a static PDF image of a grid of 4 digit numbers and keys one of those numbers in, then clicks the "search" button. I'm choosing to use a matrix of buttons because I think the button input options will (at least) come close to submitting the data (the corresponding number) to the PHP script for the search. I will soon be consulting the originator of the PHP script to see if they can help with any necessary changes to it, but what I want is the same search results provided now, but with minimal input from the user. Hope that helps. I don't know if I'm allowed to show code sections here (I'm interning for the county I.T. dept.), but if it will help, I'll try. Thanks.
    solo~ST

  4. #4
    Join Date
    May 2002
    Posts
    1,254
    If you still manually key in the 4 digit number then I don't see what changes need to be made to the php script. There are many examples that can be found on forms / php. When you click on a submit button the form fields are set as global values which can be read by the php script.

  5. #5
    Join Date
    Feb 2001
    Location
    Midwest U.S.A.
    Posts
    724
    Actually... The big change to the search method is for the user to click the corresponding button of the number, instead of keying it in by hand. The button would then send the number to the PHP script as if it were keyed in (this after the drop-down is also chosen, of course). I've tried to use the same submit parameters in the existing text entry and "search" button in the new 4 digit button, but it's not working, having commented out the text entry and search button code before hand. This why I think the PHP script may need to be modified also.
    solo~ST

  6. #6
    Join Date
    Feb 2001
    Location
    Midwest U.S.A.
    Posts
    724
    Here's the text entry code:

    <code>
    <INPUT name="CC" type="text" size="12" maxlength="24" id="CCTB" tabindex="2" />
    </code>

    Here's the "Search" button code:

    <code>
    <INPUT name="submit6" id="Button6" type="submit" value="Search" />
    </code>

    Here's the (proposed) new search method:

    Revised_PLSS_Search_04AUG2016.PNG

    Here's the code for the new search method (with the first button revised to help make it work):

    Revised_PLSS_Search_Code02_04AUG2016.PNG
    Last edited by solo; 08-04-2016 at 12:40 PM. Reason: Edited to show more code snipets
    solo~ST

  7. #7
    Join Date
    May 2002
    Posts
    1,254
    So you can add php to the HTML form to automatically create the buttons. Need to change it to php extension and any other references. Here is one example

    for ($x=501; $x<=520; $x++)
    {
    print("<INPUT name=\"submit$x\" id=\"Button$x\" type=\"submit\" value=\"$x\">");
    }

    Then in the php process script you can read the button value
    $key=$_POST["submit"];

  8. #8
    Join Date
    Feb 2001
    Location
    Midwest U.S.A.
    Posts
    724
    Getting back to the user interface... I've seen the vast majority of web searches setup like this...

    1. Make a selection, and/or type something in.
    2. Make another selection (and on, and on... ).
    3. click a "Search" button.

    So, what I'm trying to do is have a user interface without the extra "Search" button completion. I've seen this at the W3Schools site... This way:

    http://www.w3schools.com/html/tryit....ml_form_submit

    Versus this way:

    http://www.w3schools.com/tags/tryit...._button_value2

    It's that second method that's almost working, but not quite. We've go it down to a search that comes up empty, with no errors. So now I have to tweak the button parameters to sent the correct information to the PHP script. Still working, still learning.
    solo~ST

  9. #9
    Join Date
    May 2002
    Posts
    1,254
    A simple example
    <form action="script.php" method="post">
    <button name="subject" type="submit" value="501">501</button>
    <button name="subject" type="submit" value="502">502</button>
    </form>

    And in your php script you can use
    $key=$_POST['subject'];

  10. #10
    Join Date
    Aug 2016
    Posts
    1
    You could use a bit of javascript to store the values and store them whenever you change from the dropdown menu.

  11. #11
    Join Date
    Aug 2016
    Posts
    1
    This is solo (the OP for this post)... Somehow, my password and email got blown away on this forum (sad, because I've had that user ID since 2002, I think :-P ). Anyway...

    I and my coworkers GOT IT WORKING!!! A button click from a matrix of buttons sends the correct input to the PHP script, and thereby executes the MySQL search as before. We used POST to get the data there securely, and the person who made the change request is pleased with the result.

    In my extensive searching for how to do this task, I've seen a lot of "gotta use JavaScript", or "gotta use Ajax" in between the front-end HTML and the back-end PHP, and that's fine if it works for you, but all I had to do was find the correct variable value to send, and send it via the button parameters. I have to give credit to my coworkers for seeing what I was trying to do, and tweaking the script(s) to make it work... These PHP scripts are really over my head right now. More learning, I think (as Dumbledore would say ;-D ) . Thanks for all the input (and your patience also), the community here is still great.

Posting Permissions

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