|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP Dynamic Drop Down Boxes Help Please
I am Looking to do a dropdown Boxes array in php mysql
Year Make Model Description and Link to do something like this if year = 2000 show ford - chevy ........ if ford is selected show car - truck if truck is selected show f-150 - f-250- if f-250 selected show Link to site I have seen this in dropdown boxes and the page does not change here is what I have been playing with but it shows up blank. It was not my code but code I had sugested to me Pleae look and let me know what i am doing wrong Index.php <? include("config.php"); $conn = mysql_connect($host, $user, $password); mysql_select_db($dbname); ?> <html> <head> <title>User Page</title> </head> <body> <? $vvar = array(); $vvar[0] = ""; for($i = 1;$i <= $maxSub;$i++) { $vname = "v" . $i; if (isset($_GET[$vname])) { $vvar[$i] = $_GET[$vname]; } else { break; } } ?> <script type="text/javascript"> <? $jsv = array(); $jsv[0] = "?"; for($i = 1;$i <= $maxSub;$i++) { $jsv[$i] = $jsv[$i-1] . $vvar[$i-1] . "&v" . $i . "="; ?> function select<?="v" . $i?>(v1) { window.location = "<?=$jsv[$i]?>" + v1; } <? } ?> </script> <form action="index.php" method="GET"> <table border="0"> <? $parent = 1; $str1 = ""; for($i = 1;$i <= $maxSub;$i++) { $next = 0; if ($parent != 0) { $q1 = "select child_id from relation where parent_id='$parent' order by child_id"; $r1 = mysql_query($q1) or die(mysql_error()); if (isset($vvar[$i])) { $sel = $vvar[$i]; $next = $sel; } else { $sel = 0; } $str1 .= "<option value=\"0\">Select Option</option>"; while ($arr1 = mysql_fetch_assoc($r1)) { $id1 = $arr1['child_id']; $q2 = "select name from node where id = '$id1'"; $r2 = mysql_query($q2) or die(mysql_error()); $arr2 = mysql_fetch_assoc($r2); $n2 = $arr2['name']; if ($id1 == $sel) { $str1 .= "<option value=\"$id1\" selected=\"selected\">$n2</option>\n"; } else { $str1 .= "<option value=\"$id1\">$n2</option>\n"; } } } ?> <tr> <td> <? if (strcmp($str1,"" ) == 0) { ?> <select name="choice"> <option value="0">Select Option</option> <? } else { ?> <select name="choice" onChange="select<?="v" . $i?>(this.options[this.selectedIndex].value)"> <?=$str1?> </select> <? } ?> </td> </tr> <? $parent = $next; $str1 = ""; } ?> </table> </form> </body> </html> <? if ($conn) mysql_close($conn); ?> Config.php <? $dbhost = "localhost"; $user = "lesspal_fred"; $password = "password"; $dbname = "lesspal_fred"; ?> mysql dump file SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `lesspal_fred` -- -- -------------------------------------------------------- -- -- Table structure for table `node` -- CREATE TABLE IF NOT EXISTS `node` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(100) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `node` -- INSERT INTO `node` (`id`, `name`) VALUES (1, 'root'); -- -------------------------------------------------------- -- -- Table structure for table `relation` -- CREATE TABLE IF NOT EXISTS `relation` ( `parent_id` int(10) unsigned NOT NULL default '0', `child_id` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`parent_id`,`child_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `relation` -- Please Help [PHPNET="dynamic dropdown"] Last edited by hostsb : October 21st, 2008 at 12:41 PM. Reason: added dump file |
|
#2
|
|||
|
|||
|
Hi.
This is simple code for controlling list box items with Javascript. <html> <head> <script language="javascript"> function go() { document.location.href=document.f1.s1.value; } </script> </head> <body> <form method="post" name="f1"> <select id="s1" onchange="go()"> <option value="(URL address1)">yoursite1</option> <option value="(URL address2)">yoursite2</option> <option value="(URL address3)">yoursite3</option> </select> </form> </body> </html> |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Applications > PHP Dynamic Drop Down Boxes Help Please |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|