Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Populating a drop-down menu with ENUM data
Old 07-13-2010, 05:11 PM Populating a drop-down menu with ENUM data
Junior Talker

Posts: 2
Name: Angie
Trades: 0
Right, I think it might be a very simple question, but just stuck in it, hope someone will shed some light on it please.

I have a MySQL database, and have a table called 'Member', there is a filed called 'Club' and it's a Enum type.

Each member will belong to a club, I have managed to

1. Display the selected member's club.
2. Display all the club in a drop-down list.

The problem is, I need to combine the two result together, you know, like normal drop-down list where you see your current club, as well as other club so you can change the club if you want to.

The code for 1. Display the selected member's club. as follows

PHP Code:
 <?php $updatememid $_GET["MEMNUMBER"]; ?>
 <?php
    $sql 
"SELECT * from MEMBER where MEMNUMBER='$updatememid'";
    
$result=mysql_query($sql);
    
$num=mysql_num_rows($result);
    
mysql_close();    
    
$first=mysql_result($result,$i,"FN");
    
$last=mysql_result($result,$i,"LN");
    
$club=mysql_result($result,$i,"CLUB");
?>

    <form>
    <table class="mytable" width=95%  cellspacing=1px cellpadding="2" >
      
      <tr><td colspan="7"><h1>Member Details for <?php echo $first." ".$last;?></h1></td></tr>
      <tr>
      <th width="133">First Name</th>
      <th  width="81" height="32" >Last Name</th>
      <th   width="143" >Club</th>
      </tr>
      <tr>
      <td><input name="firstname" type="text" id="firstname" value="<?php echo $first;?>"/> </td>
      <td><input name="lastname" type="text" id="lastname" size="15" value="<?php echo $last;?>"/> </td>
      <td><input name="club2" type="text" id="club" value="<?php echo $club;?>"/></td>
      </tr> 
     </table>
     </form>
The code for 2. Display all the club in a drop-down list as follows

PHP Code:
<?php
//adapted from http://www.sitepoint.com/forums/showthread.php?t=62600
// get ENUM values String from specified DB table column using my Database Class
// (using substituted table and col names.)

function getEnumFieldValues($tableName$fieldName){
$field_query mysql_query("show columns from $tableName where Field='$fieldName'");
if(
mysql_num_rows($field_query) <= 0) return false;
$fieldDetail mysql_fetch_array($field_query);
$type preg_replace('/(^set\()|(^enum\()/i'''$fieldDetail['Type']);
$enumFields substr($type0, -1);
$enumFields ereg_replace("'","",$enumFields);
$fieldSplit split(','$enumFields);
return 
$fieldSplit;
}
$enumFields getEnumFieldValues('MEMBER''CLUB');
echo 
'<select name="club">';
foreach(
$enumFields as $value){
echo 
'<option value="' $value '">' $value '</option>';
}
echo 
'</select>';
?>
So here is the question, how do I combine the two code? I've tried to put the second one with the first one, apparently, the getEnumFieldValues() query is not executing after the first query $sql = "SELECT * from MEMBER where MEMNUMBER='$updatememid'";

Someone shed some light please?

Thanks

Last edited by Angie8304; 07-13-2010 at 05:20 PM.. Reason: click sumbit by accident
Angie8304 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-13-2010, 08:16 PM Re: Populating a drop-down menu with ENUM data
Junior Talker

Posts: 2
Name: Angie
Trades: 0
ahh..never mind...sorted it out.
Angie8304 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Populating a drop-down menu with ENUM data
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22816 seconds with 12 queries