Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Get dropdown value when editing user

    Hey guys, I am in need of some help, I have a table where it shows the people that have signed into a patient program.

    Here is how it looks:



    Right now if you look in the Location column, it says 8 instead of the last option in the dropdown being Manalapan.

    Here is how the database table looks for offices location:



    I would like to grab the office_name data from the database while retrieving the patient information in the table,from the table patients:



    It is stored in the database as pat_loc and this one is 8.

    In the end, I want it to say the name of the office, not the number it is stored at, first getting it from the patient table then going to the office table for the name.

    Is there such a thing that can be done?

    If needed, I will show my current code to see where it needs to be added.
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,377
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    What is the column type for pat_loc?
    If it's integer, you'll have to change it ... as the text name is not an integer.

    we'll have to see more code.
    I suspect your dropdown location select shows the textual location, but the values are the office_id. Maybe changing the values of the dropdown options to the text name and making sure pat_loc column is perhaps VARCHAR(16) would be the only necessary changes?

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Easier fix, just join the two tables together and then you'll have the office_name set in each row matching what is set for the office_id:

    select * from patients join pat_loc on pat_loc = office_id

    Quote Originally Posted by bucket View Post
    In the end, I want it to say the name of the office, not the number it is stored at, first getting it from the patient table then going to the office table for the name.

    Is there such a thing that can be done?
    Don't do it, it'll be trouble. Say you end up with 20-30,000 patient records. The moment you want to change the office name mysql will have to cycle through every record and update the affected ones. Not good - especially on a busy database server.

    Leave you layout as it is and just use a join. By doing what you're asking you'd be taking a step backwards. The way it's setup now makes it a lot easier - if you rename an office you only rename one record and all the others will use it with minimal hassle.
    Last edited by tangoforce; 06-29-2013 at 10:19 AM.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

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