Skip to content
Advertisement

PHP/MySQL: Get name for specific ID

I am a beginner to MySQL and Im trying to retrieve a name for a specific ID.

Here is how my database looks like:

I have a table of contacts which contains ID, first and last name.

I want to retrieve the first and last name for a specific ID in the same form.

So I want to end up with a form of options and the option value will be the first name for each ID.

For example:

JavaScript

The values are the ID’s.

and my PHP:

JavaScript

in my actual example I get the first and last name of the last’s person in the database only.

So how can I retrieve the first and last name for specific ID’s of which I assign in my form (?)

Advertisement

Answer

This is because your while loop is overwriting $first and $last every single time. Try

JavaScript

And in HTML (EDITED):

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement