Jump to content

saving a variable from the selected option in a datalist


michaelfurey

Recommended Posts

I would like to connect two html datalists each other.

 

For example starting from a table like that obtained with a SQL query::

 

+----+---------+--------+--------+
| ID |  Name   | Country| Gender |
+----+---------+--------+--------+
|  1 | Michael | USA    | M      |
|  2 | John    | USA    | M      |
|  3 | Michele | Italy  | M      |
|  4 | Carlo   | Italy  | M      |
|  5 | Pablo   | Mexico | M      |
|  6 | Lucy    | USA    | F      |
+----+---------+--------+--------+
SELECT *
FROM genders

I would like to select in the first datalist one country in order to see in the second datalist only the names of the persons living in that country. So if I select USA in the first datalist in the second one I should see only the names Michael, John and Lucy.

I suppose that an easy way to do that is saving the selected option of the first datalist (for example USA) in a variable ($country_selected) and to modify the SQL query to get the data of the second datalist adding a where clause (where=$country_selected)).

But my problem is that I don't know how to create $country_selected... is it possible with PHP?
Link to comment
Share on other sites

I forgot to specify that I should get the selected country from a similar html datalist tag:

<datalist id=country_data></datalist>
And get the selected value to reduce the name options of the second datalist:
<datalist id=name_data></datalist>

In other words I should connect both datalists each other.

Link to comment
Share on other sites

I forgot to specify that I should get the selected country from a similar html datalist tag:

<datalist id=country_data></datalist>
And get the selected value to reduce the name options of the second datalist:
<datalist id=name_data></datalist>

In other words I should connect both datalists each other.

I would suggest doing some more research. It sounds like you need to learn some basic mysql/pdo, php, and html.    Here's a decent reference for PDO. There's a ton of php/html tutorials out there. 

http://www.dreamincode.net/forums/topic/214733-introduction-to-pdo/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.