Jump to content

drop down box


ferlicia

Recommended Posts

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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();
}
?>

Link to comment
Share on other sites

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();

                        }

                        ?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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();
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.