Skip to content
Advertisement

How to fetch full row associated with a column which is selected in dropdown list?

I have made a dropdown list which fetches data (name) from database and displays in options of dropdown list. Now I am trying to fetch full row of that selected name from the list and want to save each data into a variable for further usage. Can anyone guide me… This is my first project in PHP/MySQL, please help me…

Here is my code for dropdown list:

JavaScript

I have managed to fetch the name and store it into a variable:

JavaScript

Which I have managed to get echo in another page (sel.php):

JavaScript

But how can I store all values of that particular row, for example:

JavaScript

etc etc

Advertisement

Answer

$_POST['data'] is an array of names, since you filled it with $data['name'] on your previous script.

There is no more data to store than the names… for that, you could for instance, serialize the record:

JavaScript

Now you’ll be getting an array of serialized records on the $POST['data'] parameter:

First, unserialize: $curdata = unserialize($selected);

Then access whatever field you need echo $curdata['age'];

Oh, and bear in mind this, if you assign $curdata to $selected inside a foreach… $curdata will always be the last $POST['data'] element, I don’t think you need the foreach in this case.

Advertisement