michaelfurey Posted March 23, 2017 Share Posted March 23, 2017 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? Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted March 23, 2017 Share Posted March 23, 2017 Do you know about http://php.net/manual/en/book.pdo.php? If not learn. It is not difficult, and will make things much easier for you. Ask questions as needed. $stmt=$pdo->prepare('SELECT Name, Gender FROM your_table WHERE Country=?'); $stmt->execute([$_GET['Country']]); $stmt->fetchAll(); Quote Link to comment Share on other sites More sharing options...
michaelfurey Posted March 23, 2017 Author Share Posted March 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 23, 2017 Share Posted March 23, 2017 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/ Quote Link to comment Share on other sites More sharing options...
benanamen Posted March 23, 2017 Share Posted March 23, 2017 What you are talking about is called a Chained Select. Look it up. Quote Link to comment Share on other sites More sharing options...
michaelfurey Posted March 24, 2017 Author Share Posted March 24, 2017 What you are talking about is called a Chained Select. Look it up. Yep that's the right title of the topic. I suppose that you can create "quite" easily a Chained Select with Javascript and Ajax.. I was wondering if with PHP it's the same. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.