michaelfurey Posted August 28, 2017 Share Posted August 28, 2017 This is my PHP code: echo "<table>";form($current_php); $cit=do_order("select * from country_itemize_types"); echo "<tr><td>Description: </td><td><select name='descr_ger' id='descr_ger'>"; $descr_sql=do_order("select distinct description from country_itemize_types"); while ($descr_arr=mysql_fetch_array($descr_sql)){ echo "<option>" . $descr_arr['description'] . "</option>"; } echo "</select></td></tr></table>"; And this is my mysql table named country_itemize_types (the table has thousand rows but I pasted here only few lines...): +-----+------+--------------+---------+------------+----------+----------+------------------+ | uid | type | description | country | field | priority | datatype | option | +-----+------+--------------+---------+------------+----------+----------+------------------+ | 1 | 12 | travelcost | ger | vehicle | 1 | char | car;bus;airplane | | 2 | 12 | travelcost | ger | distance | 2 | decimal | | | 3 | 12 | travelcost | ger | times | 3 | integer | | | 4 | 12 | travelcost | ger | cost | 4 | decimal | | | 5 | 12 | randomcost | ger | earthquake | 1 | char | weak;strong | | 6 | 12 | randomcost | ger | seaquake | 2 | char | weak;strong | | 7 | 12 | randomcost | ger | cost | 3 | decimal | | | 8 | 12 | marriagecost | ger | times | 1 | integer | | +-----+------+--------------+---------+------------+----------+----------+------------------+ I would like to create a select tag containing all the descriptions of the table (see the php code above) and when the user selects an option on this select tag should appear some input tag. For example if the user selects from the dropdown menu "travelcost" should appear 4 new input tags (vehicle, distance, times, cost). If the user selects "marriagecost" should appear only one new input tag (times). How can I do that? I suppose that I have to run a sql query with javascript or something similar but I am a newbie in javascript... Quote Link to comment https://forums.phpfreaks.com/topic/304743-php-javascript-mysql-connection/ Share on other sites More sharing options...
ginerjm Posted August 28, 2017 Share Posted August 28, 2017 What about doing it in stages? Show the user the first dropdown only and let them select an option and click on a submit button. Then you receive their selection and output a 2nd page with that choice along with all the items that match it. Sure - it will refresh the screen, but you can avoid the JS/Ajax step this way. Quote Link to comment https://forums.phpfreaks.com/topic/304743-php-javascript-mysql-connection/#findComment-1550292 Share on other sites More sharing options...
Sepodati Posted August 28, 2017 Share Posted August 28, 2017 I don't see any point to the first query. You're not doing anything with it unless there's additional code you're not showing. Without JS/ajax, you'll have to create your first <select> similar to what you're doing. Then, after the form is submitted, in your processing code, validate $_GET['descr_ger'] using the filter_* functions and add a WHERE clause to your query referencing the value. You'll want to check out PDO or the mysqli functions to create that query securely. Stop using the mysql() deprecated functions. From the results of that query with the WHERE clause limiting results to a matching descriptive value, you can create all of the other input boxes you want. -John Quote Link to comment https://forums.phpfreaks.com/topic/304743-php-javascript-mysql-connection/#findComment-1550296 Share on other sites More sharing options...
michaelfurey Posted August 30, 2017 Author Share Posted August 30, 2017 Uhm yes the row in the second line is useless because I forgot to delete it. Yep probably I will follow your instructions because I don't want to use JS/Ajax step! Quote Link to comment https://forums.phpfreaks.com/topic/304743-php-javascript-mysql-connection/#findComment-1550383 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.