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($type, 0, -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