473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Populating form item from SQL enum set

Hi

I am not even sure if it is at all possible, and I can't find the stuff I am
looking for, probably using the wrong search keys. WAMP machine (XP,
2.50.2, 4.1.5, 5.0.2)

I have a field in the MySQL table 'members':
"membertype" enum ('adult','student','senior','child','honour')

Sofar the form used for the db only has text fields, and the data entry user
relies on IE's autocomplete to always select a valid entry for the field. I
quick fixed this script so it at least checks the validity.

I'd prefer to have a general solution where the input field is a dropdown
box or something (or radio buttons) populated directly with all valid enum
fields. In case the db later is altered, enum set is modified, all the forms
should change automatically.

(How) can I retrieve the enum values from the db and use them in a dropdown
? Or who has a pointer to the right place where I can find how to do this ?
Or an example simlar snippet maybe ?
THANKS!

Pjotr
Jul 17 '05 #1
3 6955
I've used this once, but it's a bit ugly so here's to hoping a better
solution comes along :)

<?php

$sql = "SHOW COLUMNS FROM members LIKE 'membertype'";
$qry = mysql_query($sql);
$res = mysql_fetch_object($qry);
// This returns a row with a field 'Type' containing 'enum(...)'

$res->Type = str_replace('enum', 'array', $res->Type);

eval(" \$memberTypes = $res->Type; ");
foreach($memberTypes as $type) {
echo "<option...etc."
}
?>
Pjotr Wedersteers wrote:
Hi

I am not even sure if it is at all possible, and I can't find the stuff I am
looking for, probably using the wrong search keys. WAMP machine (XP,
2.50.2, 4.1.5, 5.0.2)

I have a field in the MySQL table 'members':
"membertype" enum ('adult','student','senior','child','honour')

Sofar the form used for the db only has text fields, and the data entry user
relies on IE's autocomplete to always select a valid entry for the field. I
quick fixed this script so it at least checks the validity.

I'd prefer to have a general solution where the input field is a dropdown
box or something (or radio buttons) populated directly with all valid enum
fields. In case the db later is altered, enum set is modified, all the forms
should change automatically.

(How) can I retrieve the enum values from the db and use them in a dropdown
? Or who has a pointer to the right place where I can find how to do this ?
Or an example simlar snippet maybe ?
THANKS!

Pjotr

Jul 17 '05 #2
On Fri, 29 Oct 2004 18:31:07 +0200, "Pjotr Wedersteers" <pj***@wedersteers.com>
wrote:
I am not even sure if it is at all possible, and I can't find the stuff I am
looking for, probably using the wrong search keys. WAMP machine (XP,
2.50.2, 4.1.5, 5.0.2)

I have a field in the MySQL table 'members':
"membertype" enum ('adult','student','senior','child','honour')

Sofar the form used for the db only has text fields, and the data entry user
relies on IE's autocomplete to always select a valid entry for the field. I
quick fixed this script so it at least checks the validity.

I'd prefer to have a general solution where the input field is a dropdown
box or something (or radio buttons) populated directly with all valid enum
fields. In case the db later is altered, enum set is modified, all the forms
should change automatically.

(How) can I retrieve the enum values from the db and use them in a dropdown
? Or who has a pointer to the right place where I can find how to do this ?
Or an example simlar snippet maybe ?
THANKS!


http://groups.google.com/groups?selm...&output=gplain

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
brommer wrote:
I've used this once, but it's a bit ugly so here's to hoping a better
solution comes along :)

<?php

$sql = "SHOW COLUMNS FROM members LIKE 'membertype'";
$qry = mysql_query($sql);
$res = mysql_fetch_object($qry);
// This returns a row with a field 'Type' containing 'enum(...)'

$res->Type = str_replace('enum', 'array', $res->Type);

eval(" \$memberTypes = $res->Type; ");
foreach($memberTypes as $type) {
echo "<option...etc."
}


TY, it works, and indeed doesn't look very elegant, but hey, it will do. The
other hint (by andy) has the same principle. I'll dive into the MySQL stuff
another time to see if I can find some more useful stuff on this matter.

again Thanks, both!
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
2
by: Roger | last post by:
Hi, I'm trying to populate an array with color names. I keep getting an error. Here is the line that fails: Dim Colors As String() = Enum.GetValues(enumColor.GetType())
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
0
by: Duderino82 | last post by:
$sql = "SHOW COLUMNS FROM table LIKE 'subject' "; $qry = mysql_query($sql) or die("Query not valid: " . mysql_error()); $res = mysql_fetch_object($qry); // This returns a row with a field 'Type'...
0
by: Paul Hadfield | last post by:
I'm looking for thoughts on the "correct" design for this problem (DotNet 2.0 - in winforms, but that's not so important). I've got two combo boxes (combo1 and combo2), both are populating via...
1
Gyro
by: Gyro | last post by:
Hi all, I'm a php newbie and have read various posts/articles on populating select lists dynamically from a db table. However, I cant seem to get it working in the way I want... I have 3 select...
12
by: wideasleep | last post by:
Greetings all, I am fairly new to Access but am learning quick by just using it at work while I'm recovering from a work injury. I am using Access 2007 on Vista Home Premium. Here's a long...
1
by: chandhseke | last post by:
Hi Folks, I have designed a dynamic drop down list but having problems since it is not working as intended. Please help <html> <head> <Script language="Javascript"> var Select = new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.