Results 1 to 10 of 10

Thread: Drop down list

  1. #1
    Join Date
    Jul 2003
    Posts
    16

    Question Unanswered: Drop down list

    I am new to PHP and MySQL, however, have extensive knowledge in MS Access. What I have in mind may not be possible, and after searching the web I suspect it isn't. I thought I'd ask others before giving up. Here's what I have. The database is a law enforcement case management database. In the main table up to 5 crimes can be stored, linked with foreign keys to another table.

    In Access it is easy to reference the sub-table in a combo box to select a code section which stores the foreign key in the main table. If the code section you want to use is not in the list, an event is triggered, giving the user a pop up to add the new code section. When the pop up is closed, it requeries the combo box and the user will see the new information in the list.

    Is it feasible to do something like that in PHP? If not, any suggestions? I'm trying to make it a simple for the user as possible. Since they enter other info before getting to the crimes section I don't want them to lose what they have typed because the code section is not already in the database.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I'm certain you can implement something like this in PHP.
    The first thing you need to do is work out how you're going to fill your combobox dynamically. What I suggest you do is open your recordset and loop through the results and add each item to the drop separately.

    The event in access is called something like OnNotInList, and I don't believe there is anything in php that does the same thing...

    ...However, to turn the problem on it's head - why not simply have a final selection added to the drop down with a caption of "Other..." and when this is selected, you can prompt the user to enter a value (make a textbox and submit button visible, for example).

    Once the user submits the value, you will have to go about validating the entry (don't forget to block SQL injection and check if the value already exists). Then building your SQL insert statement, execute it and reload the page.

    Anyway, I hope this helps - let me know how you get on
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    doing what you want to do in any web app is a bit fiddly.. it can be done

    there are two ways..

    ..the traditional server centric model.
    the user does some stuff in the browser... that page gets sent back to the server the server processess the user input in a script and takes appropriate action. as you users may well have started some form of data entry in the first form, then you can retain those values for the user. this can be done through say using a cookie, storing the values in the db, or resending the values to the user as part of the action done by the server. You can set the value of any input control (be it a text box, list box or whatever by setting the value of that control to the required variable. So you could have an item in your drop down list which is 'not in this list'. you sever script could then test the 'other' box to see if there is anything in it and write that to the crime type table, and then pull that key from the newly inserted crime type

    ..the more modern hybrid using javascript and PHP (or any other scritping /web langauge) .. the so called AJAX model
    there you can get closer to the traditional client server architectuire you are used to. efffectively you write some javascript that provides the events (or at least most of the useful events) that you are used to in Access. You javascript intercepts the combo box not in this list selection and then brings up say a pop up box, or enables the 'other' box to be populated. you then send those reults to the server, to update the crime type, that script returns the new combo / listbox which some javascript inserts into the existing page on the users browser. be warned though unless you have the right debuggin tools developing for PHP & ALAX can be a real pain.

    one thiog to bear in mind is that not all browsers support Javascript, or at tleas th same Javascript, not all browsers accept Javascript, and Javascript isn't accpetable for security validation... its fine, it doens the job, but you still need to check on server before you accept abthing

  4. #4
    Join Date
    Jul 2003
    Posts
    16

    That's what I thought

    In my limited understanding, that's about what I thought would have to happen. Since the program will run on an intranet, java versions won't be a problem. Thanks for the reply.

  5. #5
    Join Date
    Jul 2003
    Posts
    16
    georgev, now you've got me thinking. specifically, turning it on its head. perhaps the answer lays in having a separate page to add the charges, then the user can go back to the main page where I can echo the list of charges onto the page. that would eliminate the need to have popups.

  6. #6
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Don't confuse java with javascript... potential pitfall there

  7. #7
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Hopefully i'll get around to laying some more ideas out there tomorrow (being late in the day now) but from personal experience in the industry stay away from javascript and try and get everything done server side (in the PHP).

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by maninblues
    georgev, now you've got me thinking. specifically, turning it on its head. perhaps the answer lays in having a separate page to add the charges, then the user can go back to the main page where I can echo the list of charges onto the page. that would eliminate the need to have popups.
    There's always a dozen ways to skin a cat...





    ...I never said that all 12 would be good ways!
    George
    Home | Blog

  9. #9
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I think part of the issue he is that you're moving from a desktop app to a stateless web app.

    What i think you need to do there is separate out those parts.
    e.g. Adding a new type into your combo box should be part of the administration of the system, and shouldn't occur while you are filling in a form.

    So really you'd be looking at have a page to add new types. Type the text in a box and new type is added to your database. Now go to your form and fill it in and that options should be available in the combo box.

    Of course you could use Ajax/PHP but if you're going to go down that road you should really look into JQuery. In theory you should be able to add in another option to your combo box called "Add new type". Which could have a JQuery action assigned to it to open up a new div box (on top of your current screen), with the html of new input box, which when submitted makes an Ajax call, pushing the new info into the DB, and then OnGoodResult closes that div box and leaves you exactly where you were previously. Of course you would then have to chain another action onto the end to repopulate that dropdown box again, i.e. another stacked Ajax call to retrieve those options (in XML ??) and use JQuery to rebuild the internals of that option box. Do-able, just fiddly and prone to problems.

  10. #10
    Join Date
    Jul 2003
    Posts
    16
    Thank you all, I think I can see now how the complexity will cause far too many headaches. I think I'll leave this one for the "golden ring" LOL

Posting Permissions

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