hello.. does anyone know about dynamic dropdown menus? if i have a table with people names for example table "people" with columns name , surname , age... how can i create a dynamic dropdown menu with the ages of this table? i use php+html+mysql in the same project..thanks
Man! you got a long way to go if you're asking this question. I'm not going to give you the code to use it as I think it would be a waste of my time but I will say is, try reading a book on it first. Basically, the css or javascript is what you need to code you dropdown menu, and you use php to get the data from mysql and display it in this dropdown menu. Or you can just use the html select option instead of the css and javascript dropdown menu
thanks for answering!! i have not to do that with javascript..only with html called by http.. my problem is that ive already make a code-part for the dynamic list in php $db = new mysqli("localhost", "root","" , "mycompany"); if ($db->connect_errno) { echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error; } else { $sql = "SELECT dept_name FROM department"; $result_db = $db->query($sql); if (!$result_db) { echo $db->error . ' Error perform query!'; } else { echo '<select name="dept_name">'; echo '<option value="">Select...</option>'; while ($row = $result_db->fetch_object()) { echo '<option value="' . $row->dept_name . '">'; echo $row->dept_name; echo '</option>'; } echo '</select>'; } } PHP: but i have to change it so it will be html code called by php programme.. :/
i dont know if i explained it very well.. i just want to have php code which call the html programme.. the programme "structure" will be in html and this will be nested in php programme..for example, i want to keep the code i wrote before but i want to be html nested in php
You still haven't explained it just right. From what I could gather, you might want to use ajax. Do you want it to automatically update the dropdown?
Well my friend, you will need to learn javascript and use ajax. It's not that bad if you get the hang of it
thank you for your help.. i searched for some tutorials about ajax and javascript and i found sth and changed a little my code to this $html='<HTML><HEAD><TITLE>Question 3</TITLE></HEAD>'; $html.='<BODY>'; if ($db->connect_errno) { $html.='"Failed to connect to MySQL: (" . $db->connect_errno . ") "'; $db->connect_error; } else { $sql = 'SELECT dept_name FROM department'; $result_db = $db->query($sql); if (!$result_db) { $html.= $db->error . ' Error perform query!'; } else { $html.='</BR><B><CENTER>Department: <select name="dept_name"></CENTER></B>'; while ($row = $result_db->fetch_object()) { $html.='<option value="' . $row->dept_name .'">'; $html.='<CENTER>'.$row->dept_name.'</CENTER>'; $html.='</option>'; } $html.='</select>'; $html.='</BODY></HTML>'; } } print $html; PHP: and i think it works.. but i hope it is what i wanted