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,""); ?> Quote Link to comment 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... Quote Link to comment 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 .... ?> Quote Link to comment 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; } ?> Quote Link to comment 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) Quote Link to comment 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... Quote Link to comment 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> Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment 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; } Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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,""); Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Are you getting any errors? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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>"; Quote Link to comment 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>"; Quote Link to comment Share on other sites More sharing options...
atl_andy Posted December 14, 2007 Author Share Posted December 14, 2007 Thanks teng84....fixed. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 YAY, mark topic as solved please. Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Share Posted December 14, 2007 Why not do selections? Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.