I have mySQL database called phones and I have created table +-----------+-------+-------+ | Phone |design | weight| +-----------+-------+-------+ | S500i |slider | 90 g | | P990i |bar | 120 g | | M600i |bar | 100 g | +-----------+-------+-------+ Code (markup): then I have a dropdown menu: <FORM NAME="myform1"> <SELECT NAME="mylist1"> <OPTION VALUE="s500i">Sony Ericsson S500i <OPTION VALUE="p990i">Sony Ericsson P990i <OPTION VALUE="m600i">Sony Ericsson M600i </SELECT> </FORM> So, what I want to do is that when user for instanse selects "Sony Ericsson S500i" from the dropdown menu I want get the data from my mySQL database and show it. I'm new with php and mySQL but if I can have some help, I'm sure I can do this What is the best way to do this?
i'm trying to learn php and mysql, so, this may not be the best answer. (would also like critique by someone if this does not work at all). i think first you need to grab the value for the mysql db $mylist1=$_POST['mylist1']; Code (markup): after you get the submitted answer (i assume there is a submit button? or are you trying to get this with AJAX? if so, i didnt read anything about php+ajax yet, so i can't help you there) select the key from the database - also you dont have your table name specified $info = mysql_query("SELECT * FROM Phone table_name WHERE Phone='$mylist1'"); if (mysql_num_rows($info) > 0) { echo "<table cellpadding=10 border=1>"; while ($row = mysql_fetch_assoc($info)) { echo "<tr>"; echo "<td>".$info['Phone']."</td>; echo "<td>".$info['design']."</td>; echo "<td>".$info['weight']."</td>; echo "</tr>"; } Code (markup): unsure how that will work :\
You have several options. Firstly, and my favourite , would be to use AJAX and have the data displayed from the database without a page reload. The easiest way would be to have a PHP if condition. EG: if($_POST) { $query = mysql_query("SELECT * FROM phones WHERE Phone = '{$_POST['mylist1']}'"); while($r = mysql_fetch_array($query)) { echo $r['Phone']." ".$r['design']." ".$r['weight']."<br>"; } } Regards,