segyn Posted April 25, 2007 Share Posted April 25, 2007 I can't get the info from table departments to show up in the drop down menu. Pls. help. here is code odbc.php <?php $odbc = odbc_connect ('Tools', '', '') or die('Could Not Connect to ODBC Database!'); ?> <? if(!function_exists('odbc_fetch_array')) { function odbc_fetch_array($result, $rownumber=-1) { if (PHP_VERSION > '4.2') { if ($rownumber < 0) { odbc_fetch_into($result, $rs); } else { odbc_fetch_into($result, $rs, $rownumber); } } else { odbc_fetch_into($result, $rownumber, $rs); } $rs_assoc = Array(); foreach ($rs as $key => $value) { $rs_assoc[odbc_field_name($result, $key+1)] = $value; } return $rs_assoc; } } ?> new iron.php <?php require_once('odbc.php'); $result = odbc_exec($odbc,"SELECT * FROM Departments") or die (odbc_errormsg()); $pulldown = '<option value =$row[D_department]'; while($row = odbc_fetch_array($result)) { $pulldown .='<option value= $row[D_department]></option>'; } odbc_close($odbc);?> <html> <head> <title>New Irons</title> <link rel=stylesheet type="text/css" href="http://192.168.1.56/wod.css"> </head> <body vlink="blue" alink="blue" bgcolor="silver"> <table border="1" bgcolor="silver" align="center"> <tr> <td rowspan="20" valign = "top"><img src="http://192.168.1.56/logo_sm.gif" align="left"/></td> <td colspan="2" class=titleline valign="top">Add New Iron</td> </tr> <tr> <form action="NewIron.php" method="post"> <td>SI No:<td> <input type="text" name="SiNo" > </tr><br> <tr> <td>Watts: <td> <input type="text" name="Watts"> </tr><br> <tr> <td>Department: <td><select name="Dept"> <?php echo $row ; ?> </select> </tr><br> <tr> <td>Status: <td> <input type="text" name="Status" > </tr><br> <tr> <td>Notes: <td> <input type="text" name="Notes" > </tr><br> <tr align="center"> <td><input type=submit Name=submit Value="Submit"> <td><INPUT TYPE=RESET NAME=RESET VALUE="Reset" ></tr></table> </form> </body> </html> to post to table <?php require_once('odbc.php'); $insert = odbc_exec($odbc, "INSERT INTO Irons2 (I_SiNo, I_Watts, I_Department, I_Status, I_Notes) VALUES ('$_POST[siNo]','$_POST[Watts]','$_POST[Dept]','$_POST[status]','$_POST[Notes]')"); echo "record added"; odbc_close($odbc); ?> Link to comment https://forums.phpfreaks.com/topic/48656-dynamic-drop-down-menu-help/ Share on other sites More sharing options...
neel_basu Posted April 25, 2007 Share Posted April 25, 2007 Please Use Link to comment https://forums.phpfreaks.com/topic/48656-dynamic-drop-down-menu-help/#findComment-238329 Share on other sites More sharing options...
neel_basu Posted April 25, 2007 Share Posted April 25, 2007 I mean Use [ code ] Link to comment https://forums.phpfreaks.com/topic/48656-dynamic-drop-down-menu-help/#findComment-238398 Share on other sites More sharing options...
gp177 Posted April 25, 2007 Share Posted April 25, 2007 Try to simplify things. Also, I would not suggest outputing an odbc error message. The less the user knows about your database the better. Below is a means of trying to do what you want and it fails without creating any havic (just an empty pull down). <?php function getPulldownItems() { $sql = "SELECT * FROM Departments" ; $conn = odbc_connect ('Tools', '', '') ; $menuItems = array() ; if($result = odbc_exec($conn, $sql) ) { while($menuItem = odbc_fetch_array($result)) $menuItems[] = $menuItem ; } return $menuItems ; } $menuItems = getPullDownItems() ; ?> <select name='myName'> <?php foreach($menuItems as $menuItem) { ?> <option value='<?php echo $menuItem['myColumnName'] ; ?>'><?php echo $menuItem['myColumnName'] ; ?></option> <? } ?> </select> Link to comment https://forums.phpfreaks.com/topic/48656-dynamic-drop-down-menu-help/#findComment-238430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.