ferlicia Posted July 25, 2011 Share Posted July 25, 2011 currently i have a drop down box with 4 column. how do i make a drop down list with the column name excluding the primary key? Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 Eh, how do you do what? You have a drop down box with 4 column... ??? You mean a table with 4 columns? How do I make a drop down list with the column name excluding primary key?... I don't know what you are saying. What is your goal here. What are you trying to make? How do expect the output to appear and how does your data look before that? Quote Link to comment Share on other sites More sharing options...
ferlicia Posted July 25, 2011 Author Share Posted July 25, 2011 lets say i have a table with ID, name, price, size. I want the drop downbox to have name, price and size. I cannot manually input because i will alter the table sometimes. Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 SELECT name, price, size FROM table Quote Link to comment Share on other sites More sharing options...
ferlicia Posted July 26, 2011 Author Share Posted July 26, 2011 after selecting, then how does the information display out Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 26, 2011 Share Posted July 26, 2011 I still don't get what you mean, you want to have name, size and price in the same dropdown box? like JOHNNY XL $5,00 PETER XXL $7,50 ??? And what is the value you would like each field to POST through your form? Quote Link to comment Share on other sites More sharing options...
ferlicia Posted July 26, 2011 Author Share Posted July 26, 2011 i want the price, name, size inside a dropdown box, not the data in the column size name price Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 26, 2011 Share Posted July 26, 2011 Either you're not explaining properly or this is a simple html question. you want a simple dropdown boy saying price, name or size? <select name="whatever"> <option value="price">price</option> <option value="name">name</option> <option value="size">size</option> </select> Quote Link to comment Share on other sites More sharing options...
teynon Posted July 26, 2011 Share Posted July 26, 2011 I think I understand what you want. I think there is an easier way to do it, but you could do this: <?php $id_link=mysql_connect("localhost", "root", ""); mysql_select_db("testing"); $sql="SHOW COLUMNS FROM `table`"; if ($query=@mysql_query($sql)) { ?><select name="blah"><?php while ($req=@mysql_fetch_array($query)) { if ($req['Key'] != "PRI") { echo "<option>{$req['Field']}</option>"; } } ?></select><?php } else { echo "Mysql error:".mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
ferlicia Posted July 29, 2011 Author Share Posted July 29, 2011 i wanted to do it as a dynamic drop down box, how can i do it? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 29, 2011 Share Posted July 29, 2011 teynon's code created a dynamic dropdown list (or combobox, whichever tickles your fancy) Quote Link to comment Share on other sites More sharing options...
ferlicia Posted July 29, 2011 Author Share Posted July 29, 2011 Hi, i have tried your code and it indeed work with displaying the tables in the database. However i have two problems now. 1) The primary key is displayed. 2) i have the action = "doSelectCritieria" but it doesnt go to the next page. why? $link=mysql_connect("localhost", "root", ""); mysql_select_db("fyp"); $sql="SHOW COLUMNS FROM `criteria`"; if ($query=@mysql_query($sql)) { ?> <select name="criteria" action="doSelectCriteria.php" method="post"> <?php while ($req=@mysql_fetch_array($query)) { if ($req['Key'] != "PRI") { echo "<option>{$req['Field']}</option>"; } } ?> <p><input name="btnsubmit" value="Submit" type="submit"></p> </select> <?php } else { echo "Mysql error:".mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 29, 2011 Share Posted July 29, 2011 hmmm.. you have no <form>. You added action="doSelectCriteria.php" method="post" to your <select> element, you also managed to put the submit button inside the select element... you need something like: <form action="doSelectCriteria.php" method="post"> <select name="blablabla"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> <input type="submit" value="Submit"> </form> Quote Link to comment Share on other sites More sharing options...
teynon Posted July 29, 2011 Share Posted July 29, 2011 Sigh... WebStyles, does this seem familiar? Haha. ferlicia, if you do what WebStyles posted above, and you still get the primary key displayed, perhaps you don't have the database setup properly. What does your table structure look like? To figure out what your table structure looks like copy and paste the code below. Once you have the output from it, copy and paste it into this form using the CODE tag. (It looks like a # when you are posting a reply.) <?php $id_link=mysql_connect("localhost", "root", ""); mysql_select_db("fyp"); $sql="SHOW COLUMNS FROM `criteria`"; if ($query=@mysql_query($sql)) { ?><pre><?php while ($req=@mysql_fetch_array($query)) { if ($req['Key'] != "PRI") { echo "<option>{$req['Field']}</option>"; } } ?></pre><?php } else { echo "Mysql error:".mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 29, 2011 Share Posted July 29, 2011 @teynon: lol. The funny thing is, ferlicia has another post on the forum that actually has the form properly done. 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.