Python - SQl query

Soldato
Joined
22 Nov 2007
Posts
4,091
Hi All

I’ve beeb making a doctor/patient appointment booking app. I have an appointment table with patient/doctor id as foreign keys, i have an admin screen where appointment details can be entered (date, time, doctor name).

I will have a drop down to display the doctor names populated with a select statement. I can’t figure out how this will work if there are two doctors with the same name when doing the sql insert( insert doctor id into appointments where doctor name = doctor id)

this is a personal project as i’ve recently finished a udemy python course fyi
 
Associate
Joined
28 Feb 2023
Posts
61
Location
liverpool
Natural keys are almost always a bad idea. Best to use either a guid ( so you can know the key in advance of insert ) or a self incrementing int.
A Dropdownlist Option can have an id attribute. Use that to hold your id for the doctor and show the name as content.
Doesn't then matter how many Dr Smiths you have.
 
Soldato
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
I agree with @andy o
You're populating the dropdown from a select statement, so just change that to include doctor id as well as doctor name. The id goes into the 'value' attribute of the select list items and the name goes into the 'text' attribute. You don't need to worry about matching up the name the user selected, you have the selected id instead which you can just pop straight into the appointment table.

But you'll also need to include @Blueball's suggestion too. Even though the code will work perfectly fine with multiple names the same because it's using ids rather than names, the user won't know which is the correct item to pick from the dropdown list if there's 2 the same. So I would include the name and partial reg number in the display but stick to using the id for the actual values selected.
 
Soldato
OP
Joined
22 Nov 2007
Posts
4,091
Natural keys are almost always a bad idea. Best to use either a guid ( so you can know the key in advance of insert ) or a self incrementing int.
A Dropdownlist Option can have an id attribute. Use that to hold your id for the doctor and show the name as content.
Doesn't then matter how many Dr Smiths you have.

I do use an auto incrementing int for the primary key
 
Back
Top Bottom