I wrote the below function to display the data from database on the list/select menu. This is a update page, where the old data from the database is pre-populated in the HTML fields.
Code: Select all
function display_mode_list($dbdata,$mod,$tableName,$lookupID,$lookupData) {
if ($mod=="del"){
if($dbdata==NULL || $dbdata=='') $dispVal="<font color='#CBCBCB'>N.A.</font>";
else $dispVal=$dbdata;
}
if ($mod=="edi"){
$queryDyn=mysql_query("SELECT * FROM $tableName");
$option="<select name='$tableName' id='$tableName'>";
while($fieldsDyn = mysql_fetch_array($queryDyn)){
$option= $option."<option value='$fieldsDyn[$lookupID]'>$fieldsDyn[$lookupData]</option>";
}
$option = $option. "</select>";
if($dbdata==NULL || $dbdata=='') $dispVal="$dbdata";
else $dispVal= $option;
}
return $dispVal;
}
ini_set('display_errors','1');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
on top of the page)...
This is the line where I'm doing a if statement to check for old value...
Code: Select all
$option= $option."<option value='$fieldsDyn[$lookupID]'."if($dbdata==$fieldsDyn['$lookupData']){echo 'selected=selected';}".>$fieldsDyn[$lookupData]</option>";
thanks folks...