atl_andy Posted December 14, 2007 Share Posted December 14, 2007 My form has a couple of drop down menus that are populated using a pgsql table. 1. How do I get the drop down menus to separate from each other? I have tried using <p> and <br />, but neither is working. Currently they are right on top of each other. 2. Is there a better way to handle this? I will be using more drop down menus on the form and would like to have the code be as tight as possible. This was the only way I could get the menus populated. disclaimer: I'm relatively new to php...only been using it for about three weeks. Any help is appreciated. <?php // Manufacturer Dropdown function create_dropdownMFR($identifierMFR,$pairsMFR,$identifierMFR,$multipleMFR="") { // Start the dropdown list with the <select> element and title $dropdownMFR = "<select name=\"$identifierMFR\"> "; $dropdownMFR .= "<option name=\"\">Select Manufacturer</option>"; // Create the dropdown elements foreach($pairsMFR AS $valueMFR => $nameMFR) { $dropdownMFR .= "<option name=manufacturer>$nameMFR</option>"; } // Conclude the dropdown and return it echo "</select>"; return $dropdownMFR; } //Connect to the db server and select a database $db_handleMFR = pg_connect('dbname=test user=user password=secret'); // Retrieve the manufacturer table data $queryMFR = "SELECT record_id, manufacturer FROM dropdown ORDER BY manufacturer"; $resultMFR = pg_query($db_handleMFR, $queryMFR); // Create an associative array based on the table data while($rowMFR = pg_fetch_array($resultMFR)) { $valueMFR = $rowMFR['record_id']; $nameMFR = $rowMFR['manufacturer']; $pairsMFR[$valueMFR] = $nameMFR; } echo "Manufacturer: "; echo create_dropdownMFR("dropdown",$pairsMFR,""); ?> <?php // Model Number Dropdown function create_dropdownModel($identifierModel,$pairsModel,$identifierModel,$multipleModel="") { // Start the dropdown list with the <select> element and title $dropdownModel = "<select name=\"$identifierModel\"> "; $dropdownModel .= "<option name=\"\">Select Model Number</option>"; // Create the dropdown elements foreach($pairsModel AS $valueModel => $nameModel) { $dropdownModel .= "<option name=modelnumber>$nameModel</option>"; } // Conclude the dropdown and return it echo "</select>"; return $dropdownModel; } //Connect to the db server and select a database $db_handleModel = pg_connect('dbname=test user=user password=secret'); // Retrieve the manufacturer table data $queryModel = "SELECT record_id, manufacturer FROM dropdown ORDER BY manufacturer"; $resultModel = pg_query($db_handleModel, $queryModel); // Create an associative array based on the table data while($rowModel = pg_fetch_array($resultModel)) { $valueModel = $rowModel['record_id']; $nameModel = $rowModel['manufacturer']; $pairsModel[$valueModel] = $nameModel; } echo "Model: "; echo create_dropdownModel("dropdown",$pairsModel,""); ?> Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/ Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 I would use a <br > to seperate the drop down menus. You should be fine with this also... Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414431 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 That's what I have been trying, but maybe I'm not putting it in the correct place. Is this correct?: <?php ... ?> <br /><br/> <?php .... ?> Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414437 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 try this <?php // Conclude the dropdown and return it echo "</select><br>"; return $dropdownMFR; } ?> Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414439 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 No luck with that either (I was trying that while you were posting) Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414445 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 No luck with that either (I was trying that while you were posting) Can you post the SOURCE of the HTML when your viewing the site? I am usually good at this stuff... Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414452 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 <html> <head> <title>Audit Form</title> <link href="style.css" type="text/css" rel="stylesheet" /> </head> <body> <fieldset class="fieldset"> <form action="subscribe.php" method="post"> <div class="div0"> <h3>Notebook Audit Form</h3><p>Project Number:<input type="text" name="projectnumber" size="10" maxlength="20" value="" />User ID:<input type="text" name="userid" size="10" maxlength="20" value="" /></p> </div> <div class="div1"> <?php // Manufacturer Dropdown function create_dropdownMFR($identifierMFR,$pairsMFR,$identifierMFR,$multipleMFR="") { // Start the dropdown list with the <select> element and title $dropdownMFR = "<select name=\"$identifierMFR\"> "; $dropdownMFR .= "<option name=\"\">Select Manufacturer</option>"; // Create the dropdown elements foreach($pairsMFR AS $valueMFR => $nameMFR) { $dropdownMFR .= "<option name=manufacturer>$nameMFR</option>"; } // Conclude the dropdown and return it echo "</select>"; return $dropdownMFR; } //Connect to the db server and select a database $db_handleMFR = pg_connect('dbname=test2 user=user password=secret'); // Retrieve the manufacturer table data $queryMFR = "SELECT record_id, manufacturer FROM dropdown ORDER BY manufacturer"; $resultMFR = pg_query($db_handleMFR, $queryMFR); // Create an associative array based on the table data while($rowMFR = pg_fetch_array($resultMFR)) { $valueMFR = $rowMFR['record_id']; $nameMFR = $rowMFR['manufacturer']; $pairsMFR[$valueMFR] = $nameMFR; } echo "Manufacturer: "; echo create_dropdownMFR("dropdown",$pairsMFR,""); ?> <?php // Model Number Dropdown function create_dropdownModel($identifierModel,$pairsModel,$identifierModel,$multipleModel="") { // Start the dropdown list with the <select> element and title $dropdownModel = "<select name=\"$identifierModel\"> "; $dropdownModel .= "<option name=\"\">Select Model Number</option>"; // Create the dropdown elements foreach($pairsModel AS $valueModel => $nameModel) { $dropdownModel .= "<option name=modelnumber>$nameModel</option>"; } // Conclude the dropdown and return it echo "</select>"; return $dropdownModel; } //Connect to the db server and select a database $db_handleModel = pg_connect('dbname=test2 user=user password=secret); // Retrieve the manufacturer table data $queryModel = "SELECT record_id, manufacturer FROM dropdown ORDER BY manufacturer"; $resultModel = pg_query($db_handleModel, $queryModel); // Create an associative array based on the table data while($rowModel = pg_fetch_array($resultModel)) { $valueModel = $rowModel['record_id']; $nameModel = $rowModel['manufacturer']; $pairsModel[$valueModel] = $nameModel; } echo "Model Number: "; echo create_dropdownModel("dropdown",$pairsModel,""); ?> <input type="submit" name="submit" value="Submit to Database" /> </div> </form> </fieldset> </body> </html> Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414456 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 I ment when your viewing the site on your browser. Right Click - View Source Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414461 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 hence the disclaimer... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Enter New Assets</title> <link href="style.css" type="text/css" rel="stylesheet" /> </title> </head> <body> <ul class="div5" id="navcontainer"> <li><a href="pc.html" target="iframe0">Add PC</a></li> <li><a href="monitor.html" target="iframe0">Add Monitor</a></li> <li><a href="notebook.php" target="iframe0">Add Notebook</a></li> <li><a href="server.html" target="iframe0">Add Server</a></li> <li><a href="printer.html" target="iframe0">Add Printer</a></li> <li><a href="home.html">Return To Main Page</a></li> </ul> <iframe name="iframe0" src="" float="right" scrolling="auto" height="100%" width="75%"></iframe> </body> </html> Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414462 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Show me the source where the drop down menus are outputed. weird, this should work just fine function create_dropdownMFR($identifierMFR,$pairsMFR,$identifierMFR,$multipleMFR="") { // Start the dropdown list with the <select> element and title $dropdownMFR = "<select name=\"$identifierMFR\"> "; $dropdownMFR .= "<option name=\"\">Select Manufacturer</option>"; // Create the dropdown elements foreach($pairsMFR AS $valueMFR => $nameMFR) { $dropdownMFR .= "<option name=manufacturer>$nameMFR</option>"; } // Conclude the dropdown and return it echo "</select><br><br>"; return $dropdownMFR; } Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414465 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 I retyped it like you suggested and it worked. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414471 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 I retyped it like you suggested and it worked. Thanks for the help. Your Welcome Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414473 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 ok, another issue popped up. "Model Number" is not showing up above the second drop down. echo "Model Number: "; // Does not show on the form echo create_dropdownModel("dropdown",$pairsModel,""); Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414495 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Are you getting any errors? Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414498 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 No, the label is just blank. Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414500 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 No, the label is just blank. What do you mean the label is blank? Does it show the drop down itself? Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414504 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 Yes, just the drop down...it looks like: Manufacturer: ..drop down [blank space] ..drop down and should be Manufacturer: ..drop down Model Number: ..drop down Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414506 Share on other sites More sharing options...
teng84 Posted December 14, 2007 Share Posted December 14, 2007 this line $dropdownMFR .= "<option name=manufacturer>$nameMFR</option>"; should be $dropdownMFR .= "<option value='manufacturer'>$nameMFR</option>"; Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414507 Share on other sites More sharing options...
teng84 Posted December 14, 2007 Share Posted December 14, 2007 and ... this line foreach($pairsMFR as $valueMFR => $nameMFR) { $dropdownMFR .= "<option value='manufacturer'>$nameMFR</option>"; } // Conclude the dropdown and return it echo "</select><br><br>"; should be foreach($pairsMFR as $valueMFR => $nameMFR) { $dropdownMFR .= "<option value='manufacturer'>$nameMFR</option>"; } // Conclude the dropdown and return it $dropdownMFR .= "</select><br><br>"; Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414510 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 Thanks teng84....fixed. Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414514 Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 YAY, mark topic as solved please. Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414516 Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Share Posted December 14, 2007 Why not do selections? Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414517 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 sorry, only the stuff he posted. my vars were screwed up. the Model Number still isn't showing. Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414518 Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Share Posted December 14, 2007 Try selections $slection= $_POST[something']; } if($something=="1") { $something="Something"; } elseif($something=="2") { $something="Something"; } else { $something="something"; } And in forms <select name='something'> <option value='1'>something</option> <option value='2'>something</option> </select> Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414522 Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 Eventually there will be quite a few items in the drop downs and I figured it would be easier to manage with a db table instead of a long select. There are other features I want to add that will select only the model numbers for particular manufacturers so the list doesn't blow up the user's screen. However, given my n00bness, will a select work better? Link to comment https://forums.phpfreaks.com/topic/81598-solved-drop-down-menus-couple-of-questions/#findComment-414524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.