Ok. Let me start by saying that I am fairly new to php but I'm learning. Having said that, please be gentle. lol
I currently have a personals sight that has a list of checkboxes in the profile content side for certain preferences. For each catagory I have asighned a numver to disteguish it from other text boxes. For example:
I like:
[ ] blue [X] red [ ]orange
I hate:
[ ] purple [ ] green [X] pink
By checking red it is given a catagory of 1 and in the profile field of red for the user in the database a 1 is placed.
By checking pink it is given a caragory of 2 and in the profile field of pink for the user in the database a 1 is placed.
Why? So that when it is displayed on the profile page it falls into the right spot.
I have written some code that works fine but it seems to me that it could be done in a more compact way.
Any suggestions would help this newbie be a better coder. Thanks.
function DisplayCheckboxData($id, $showextra, $connector){
## THIS FUNCTION RETURNS SPECIAL CHECKBOX DATA
$RetunThisData1 = "";
$RetunThisData1 .= '<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0"><tbody>';
$NumberOfRows1 = 1;
$RunThisQuery1 = "SELECT distinct fid, fCaption, fName, fType FROM frm_fields WHERE fType = 5 Order by fOrder";
$result11 = $connector->query($RunThisQuery1);
$total_num1 = $connector->fetchNumResult($result11);
while ( $row1 = $connector->fetchArray($result11) )
{
$FIELDS1[1]= $row1['fid'];
$FIELDS1[2]= $row1['fName'];
$FIELDS1[3] = Q("select caption as result from frm_fields_caption where Cid='".$row1['fid']."' AND lang='".D_LANG."' LIMIT 1",$connector);
$FIELDS1[4]= $row1['fType'];
$FieldValue1 = Q("SELECT ".$FIELDS1[2]." AS result FROM frm_users WHERE userid=$id",$connector);
if($FieldValue1 != "" && $FieldValue1 !=0){ // dont display this row if its blank
$RetunThisData1 .= '<font size=2 color=#ffffff>'.S($FIELDS1[3]) .', </font>';
if($FIELDS1[4] == 5){
if($FieldValue1 ==1){$RetunThisData1;}
}
} // end dont disply
$NumberOfRows1 ++;
}
$RetunThisData1 .='</tbody></table>';
return $RetunThisData1;
}
function DisplayCheckboxData2($id, $showextra, $connector){
## THIS FUNCTION RETURNS SPECIAL CHECKBOX DATA
$RetunThisData2 = "";
$RetunThisData2 .= '<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0"><tbody>';
$NumberOfRows2 = 1;
$RunThisQuery2 = "SELECT distinct fid, fCaption, fName, fType FROM frm_fields WHERE fType = 8 Order by fOrder";
$result12 = $connector->query($RunThisQuery2);
$total_num2 = $connector->fetchNumResult($result12);
while ( $row2 = $connector->fetchArray($result12) )
{
$FIELDS2[1]= $row2['fid'];
$FIELDS2[2]= $row2['fName'];
$FIELDS2[3] = Q("select caption as result from frm_fields_caption where Cid='".$row2['fid']."' AND lang='".D_LANG."' LIMIT 1",$connector);
$FIELDS2[4]= $row2['fType'];
$FieldValue2 = Q("SELECT ".$FIELDS2[2]." AS result FROM frm_users WHERE userid=$id",$connector);
if($FieldValue2 != "" && $FieldValue2 !=0){ // dont display this row if its blank
$RetunThisData2 .= '<font size=2 color=#ffffff>'.S($FIELDS2[3]) .', </font>';
if($FIELDS2[4] == 5){
if($FieldValue2 ==2){$RetunThisData2;}
}
} // end dont disply
$NumberOfRows2 ++;
}
$RetunThisData2 .='</tbody></table>';
return $RetunThisData2;
}
function DisplayCheckboxData3($id, $showextra, $connector){
## THIS FUNCTION RETURNS SPECIAL CHECKBOX DATA
$RetunThisData3 = "";
$RetunThisData3 .= '<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0"><tbody>';
$NumberOfRows3 = 1;
$RunThisQuery3 = "SELECT distinct fid, fCaption, fName, fType FROM frm_fields WHERE fType = 7 Order by fOrder";
$result13 = $connector->query($RunThisQuery3);
$total_num3 = $connector->fetchNumResult($result13);
while ( $row3 = $connector->fetchArray($result13) )
{
$FIELDS3[1]= $row3['fid'];
$FIELDS3[2]= $row3['fName'];
$FIELDS3[3] = Q("select caption as result from frm_fields_caption where Cid='".$row3['fid']."' AND lang='".D_LANG."' LIMIT 1",$connector);
$FIELDS3[4]= $row3['fType'];
$FieldValue3 = Q("SELECT ".$FIELDS3[2]." AS result FROM frm_users WHERE userid=$id",$connector);
if($FieldValue3 != "" && $FieldValue3 !=0){ // dont display this row if its blank
$RetunThisData3 .= '<font size=2 color=#ffffff>'.S($FIELDS3[3]) .', </font>';
if($FIELDS3[4] == 7){
if($FieldValue3 ==1){$RetunThisData3;}
}
} // end dont disply
$NumberOfRows3 ++;
}
$RetunThisData3 .='</tbody></table>';
return $RetunThisData3;
}
function DisplayCheckboxData4($id, $showextra, $connector){
## THIS FUNCTION RETURNS SPECIAL CHECKBOX DATA
$RetunThisData4 = "";
$RetunThisData4 .= '<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0"><tbody>';
$NumberOfRows4 = 1;
$RunThisQuery4 = "SELECT distinct fid, fCaption, fName, fType FROM frm_fields WHERE fType = 6 Order by fOrder";
$result14 = $connector->query($RunThisQuery4);
$total_num4 = $connector->fetchNumResult($result14);
while ( $row4 = $connector->fetchArray($result14) )
{
$FIELDS4[1]= $row4['fid'];
$FIELDS4[2]= $row4['fName'];
$FIELDS4[3] = Q("select caption as result from frm_fields_caption where Cid='".$row4['fid']."' AND lang='".D_LANG."' LIMIT 1",$connector);
$FIELDS4[4]= $row4['fType'];
$FieldValue4 = Q("SELECT ".$FIELDS4[2]." AS result FROM frm_users WHERE userid=$id",$connector);
if($FieldValue4 != "" && $FieldValue4 !=0){ // dont display this row if its blank
$RetunThisData4 .= '<font size=2 color=#ffffff>'.S($FIELDS4[3]) .', </font>';
if($FIELDS4[4] == 6){
if($FieldValue4 ==1){$RetunThisData4;}
}
} // end dont disply
$NumberOfRows4 ++;
}
$RetunThisData4 .='</tbody></table>';
return $RetunThisData4;
}