473,788 Members | 2,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populating dropdown list with column names?

16 New Member
I keep getting problems with this. What i want to do is populate my dropdown list with the names of the columns in one of my database tables. Whatever i try to do i keep somehow filling it in with like 5 Array's or 5 Object's. Code is below and any help is greatly appreciated.

$query33 = "SHOW COLUMNS FROM $January";
$result33 = mysql_query($qu ery33);

<select name='os1'>
<?php
if($result33){
while($row = mysql_fetch_arr ay($result33)){
echo "<option value='$row'>". $row."</option>";
}
}
?>
</select>
Dec 10 '07 #1
4 4368
clai83
41 New Member
I keep getting problems with this. What i want to do is populate my dropdown list with the names of the columns in one of my database tables. Whatever i try to do i keep somehow filling it in with like 5 Array's or 5 Object's. Code is below and any help is greatly appreciated.

$query33 = "SHOW COLUMNS FROM $January";
$result33 = mysql_query($qu ery33);

<select name='os1'>
<?php
if($result33){
while($row = mysql_fetch_arr ay($result33)){
echo "<option value='$row'>". $row."</option>";
}
}
?>
</select>
the $row that you extracted from the mysql result has a lot more information than you realize. It not only contains the column title, but also what kind of row it is, if its a PRIMARY KEY, or UNIQUE, a bunch of stuff. You need to change1 line to your code to make this work out the way you want it to.

[PHP]
echo "<option value=\"{$row['Field']}\">".$row['Field']."</option>";
[/PHP]

You may want to check out what the $row array includes as well so you know what you are working with.

[PHP]
$result = $mysql_query($q uery);
while ($row = mysql_fetch_arr ay($result)) {
print_r($row);
}

[/PHP]

This will give you a good idea of what is inside the array so you know how to properly reference it next time

hope this helps
Dec 10 '07 #2
cherryst152
16 New Member
That worked perfectly. Thank you. One more thing though that should be easily solved, yet I am still have difficulty with....

I want to take this a step further and display certain columns when put under a specified query... a random example would be easiest to see what i mean...

January
Day Ticket Payment Guest
1 yes no yes
2 no yes yes

If i wanted the dropdown list to show only Payment when it is 'no' on Day 1.
(The dropdown list would only have 'Payment' in it based only from the Day 1 row).
Dec 10 '07 #3
clai83
41 New Member
That worked perfectly. Thank you. One more thing though that should be easily solved, yet I am still have difficulty with....

I want to take this a step further and display certain columns when put under a specified query... a random example would be easiest to see what i mean...

January
Day Ticket Payment Guest
1 yes no yes
2 no yes yes

If i wanted the dropdown list to show only Payment when it is 'no' on Day 1.
(The dropdown list would only have 'Payment' in it based only from the Day 1 row).
You basically have to find out this information by sending a query to the database

SELECT payment FROM table WHERE payment = 'no' AND day = 1

then you test how many rows you got in your mysql result with the mysql_num_rows function. If it is equal to 1 then you have a match and you know that you show display it. If it is 0 then you shouldn't display it.

something like that
Dec 10 '07 #4
cherryst152
16 New Member
it should be one row no matter what if there are unique Days (such as Day 1).
I'm just lookin to see if it's possible to display not all the column names at once, but rather specificy (maybe not even from a query--i dont really know) when a column has a certain value within a certain row and to select that certain column. maybe i shouldn't show all the columns at first and maybe there is another way to displaying column names with specifications? hope i'm not confusing too much.
Dec 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2591
by: Lamine Darbouche | last post by:
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will populate automatically the second one which is the TOWNS and when the town is selected is should populate the third one AREA) all data is in the database in one table. Any idea??? Many thanks in adavance. Lamine
1
1899
by: Patrick.O.Ige | last post by:
Doing the simple DropDown List binding using the method NextResult() But its just not populating .. what am i missing Its populating the 3 DropDwonList but no Data? Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not IsPostBack Then Dim sqlConnection As SqlConnection = New SqlConnection sqlConnection.ConnectionString =
4
8080
by: Pete Lux | last post by:
I have a drop down that populates on page load. The drop down brings in customer numbers from my local MSDE database. It does this fine, but I click a button that finds quotes for those customers and the next time I go to drop down the list, all the customer numbers are doubled (1015,1016,1017,1015,1016,1017..) How do I get that to stop? Do I have to check if it's a post back or something like that? I'm fairly new at this, if you...
1
1775
by: Mike P | last post by:
I am populating a drop down column in a datagrid on page load. Here is my code : <asp:TemplateColumn> <ItemTemplate> <asp:DropDownList ID="ddlUserName" Font-Name="Verdana" Font-Size="8pt" Runat=server DataValueField="UserName" DataTextField="UserName" DataSource='<%# GetUserList() %>'>
2
5987
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could use the System.DirectoryServices.ActiveDirectory namespace. I don't even know if this is the right way to go as I can't seem to find anything in that namespace that would help me query active directory for names. I can't use an LDAP query...
3
3848
by: Cagey | last post by:
What I'm trying for: If this selection or if click on selection (highlighted line choice/ which ever selection change) w/in query's combo dropdown list box (on Switchboard), then Open in Datasheet View, the specific underlying record's Row... showing all columns Or selected columns. For a specific row's record ONLY, Or for all Xs (same type), or for the whole data sheet (all records... includes all types then), but focus still opens...
11
7399
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and the Dropdown doesnt have any items.. The requirement is that as soon as one goes on typing the letters in the StudentName-textbox the corresponding matching names have to appear
0
1706
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my SQL statements in the Data Acess Layer to create more secure web service application. The Web service class is also in the Data Access Layer. I need to populates the 4 Dropdown list boxes on the web form from one table. I have Customer table which...
0
1398
by: jdrott1 | last post by:
'i'm trying to populate a dropdown list from a column in an odbc connection. this is what i have so far and i seem to be lost. i don't understand how to go from the data adapter to populating the drop down. dim conndb as data.odbc.odbcconnection try conndb = new data.odbc.odbcconnection conndb.connectionstring = "DSN=DBConnection" conndb.open ()
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10121
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5404
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.