작업중인 애플리케이션이 있는데, 이는 Dreamweaver CS5에서 생성되었습니다. 코드는 매우 우스꽝 스럽습니다. 사이트를 만든 사람이 도움을 줄 수 없으므로 코드를 고민하고 가능한 한 일부를 "단순화"하려고합니다. 나는 PHP로 초급 중급의 이상입니다. 마치 그렇게 어려울 수없는 것처럼 보입니다. 응용 프로그램에서 수행해야 할 작업에 대한 설명 : 고객 테이블에 데이터가 표시되어야하며 테이블에서 접두어, 접미사 및 상태가 표시되어야하지만 기본 키에 대한 자동 증가 ID가 있으며 텍스트 부분은 표시하지 않고 숫자 만 표시합니다. 따라서 전임자는 숫자를 데이터로 변환하는 else 문을 사용했습니다 (코드에서 얼마나 귀찮은 지 알 수 있습니다). 여기 내 코드가 있습니다 :MySql에서 배열로 데이터를 가져온 다음 배열의 데이터를 기존 변수와 비교합니다.
<?php require_once('Connections/customer.php'); ?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_DetailRS1 = 30;
$pageNum_DetailRS1 = 0;
if (isset($_GET['pageNum_DetailRS1'])) {
$pageNum_DetailRS1 = $_GET['pageNum_DetailRS1'];
}
$startRow_DetailRS1 = $pageNum_DetailRS1 * $maxRows_DetailRS1;
$colname_DetailRS1 = "-1";
if (isset($_GET['recordID'])) {
$colname_DetailRS1 = $_GET['recordID'];
}
mysql_select_db($database_customer, $customer);
$query_DetailRS1 = sprintf("SELECT * FROM customer WHERE id = %s", GetSQLValueString ($colname_DetailRS1, "int"));
$query_limit_DetailRS1 = sprintf("%s LIMIT %d, %d", $query_DetailRS1, $startRow_DetailRS1, $maxRows_DetailRS1);
$DetailRS1 = mysql_query($query_limit_DetailRS1, $customer) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
if (isset($_GET['totalRows_DetailRS1'])) {
$totalRows_DetailRS1 = $_GET['totalRows_DetailRS1'];
} else {
$all_DetailRS1 = mysql_query($query_DetailRS1);
$totalRows_DetailRS1 = mysql_num_rows($all_DetailRS1);
}
$totalPages_DetailRS1 = ceil($totalRows_DetailRS1/$maxRows_DetailRS1)-1;
$query = "SELECT id, state_abbr FROM state WHERE id =".$row_DetailRS1['state']."";
$result = mysql_select_db($database_customer, $customer)
or die($query."<br/><br/>".mysql_error());
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="41%" border="0" align="center" cellpadding="2" cellspacing="5">
<tr>
<td width="157">Id</td>
<td width="469"><?php echo $row_DetailRS1['id']; ?></td>
</tr>
<tr>
<td>Prefix</td>
<td><?php if($row_DetailRS1['prefix']==1) {
echo 'Mr.';}
else if($row_DetailRS1['prefix']==2) {
echo 'Mrs.'; }
else if($row_DetailRS1['prefix']==3) {
echo 'Ms.'; }
else if($row_DetailRS1['prefix']==4) {
echo 'Mr. & Mrs.'; }
else if($row_DetailRS1['prefix']==5) {
echo 'Dr.'; }
else if($row_DetailRS1['prefix']==6) {
echo 'Dr. & Mrs.'; }
else if($row_DetailRS1['prefix']==7) {
echo 'Mr. & Dr.'; }
else if($row_DetailRS1['prefix']==8) {
echo 'Drs.'; }
else if($row_DetailRS1['prefix']==9) {
echo 'Hon.';}
else if($row_DetailRS1['prefix']==10) {
echo 'Hon. & Mrs.'; }
else if($row_DetailRS1['prefix']==11) {
echo 'Mr. & Hon.'; }
else if($row_DetailRS1['prefix']==12) {
echo 'Hons.'; }
else if($row_DetailRS1['prefix']==13) {
echo 'Rev.'; }
else if($row_DetailRS1['prefix']==14) {
echo 'Rev. & Mrs.'; }
else if($row_DetailRS1['prefix']==15) {
echo 'Atty.'; }
else if($row_DetailRS1['prefix']==16) {
echo 'Atty. & Mrs.'; }
else if($row_DetailRS1['prefix']==17) {
echo 'Mr. & Atty.'; }
else if($row_DetailRS1['prefix']==18) {
echo 'Attys.'; }
else if($row_DetailRS1['prefix']==19) {
echo 'Sen.'; }
else if($row_DetailRS1['prefix']==20) {
echo 'Sen & Mrs.'; }
else if($row_DetailRS1['prefix']==21) {
echo 'Mrs. & Sen.'; }
else if($row_DetailRS1['prefix']==22) {
echo 'Sens.'; }
else if($row_DetailRS1['prefix']==23) {
echo 'Rep.'; }
else if($row_DetailRS1['prefix']==24) {
echo 'Rep. & Mrs.'; }
else if($row_DetailRS1['prefix']==25) {
echo 'Mr. & Rep.'; }
else if($row_DetailRS1['prefix']==26) {
echo 'Reps.'; }
else if($row_DetailRS1['prefix']==27) {
echo 'Mayor'; }
else if($row_DetailRS1['prefix']==28) {
echo 'Admin'; }; ?></td>
</tr>
<tr>
<td>Business Name</td>
<td><?php echo $row_DetailRS1['businessName']; ?></td>
</tr>
<tr>
<td>First Name</td>
<td><?php echo $row_DetailRS1['firstName']; ?></td>
</tr>
<tr>
<td>Spouse Name</td>
<td><?php echo $row_DetailRS1['spouseName']; ?></td>
</tr>
<tr>
<td>Last Name</td>
<td><?php echo $row_DetailRS1['lastName']; ?></td>
</tr>
<tr>
<td>Suffix</td>
<td><?php if($row_DetailRS1['suffix']==1) {
echo 'Sr.';}
else if($row_DetailRS1['suffix']==2) {
echo 'Jr.'; }
else if($row_DetailRS1['suffix']==3) {
echo 'I'; }
else if($row_DetailRS1['suffix']==4) {
echo 'II' ; }
else if($row_DetailRS1['suffix']==5) {
echo 'III'; }
else if($row_DetailRS1['suffix']==6) {
echo 'IV'; }
else if($row_DetailRS1['suffix']==7) {
echo 'V'; }
else if($row_DetailRS1['suffix']==8) {
echo 'Esq.'; }; ?></td>
</tr>
<tr>
<td>Address</td>
<td><?php echo $row_DetailRS1['address']; ?></td>
</tr>
<tr>
<td>Address Continued</td>
<td><?php echo $row_DetailRS1['addressCont']; ?></td>
</tr>
<tr>
<td>City</td>
<td><?php echo $row_DetailRS1['city']; ?></td>
</tr>
<tr>
<td>State</td>
<td><?php while($row = mysql_fetch_assoc($customer, $result)) {
if($row_DetailRS1['state'] == $row) {
echo '$row';}} ?></td>
</tr>
<tr>
<td>Zip Code</td>
<td><?php echo $row_DetailRS1['zipCode']; ?></td>
</tr>
<tr>
<td>Phone Number</td>
<td><?php echo $row_DetailRS1['phoneNum']; ?></td>
</tr>
<tr>
<td>Alt. Phone Number</td>
<td><?php echo $row_DetailRS1['altPhoneNum']; ?></td>
</tr>
<tr>
<td>E-mail</td>
<td><?php echo $row_DetailRS1['email']; ?></td>
</tr>
<tr>
<td>Board Member</td>
<td><?php echo $row_DetailRS1['boardMember']; ?></td>
</tr>
<tr>
<td>Trustee</td>
<td><?php echo $row_DetailRS1['trustee']; ?></td>
</tr>
<tr>
<td>Musician</td>
<td><?php echo $row_DetailRS1['musician']; ?></td>
</tr>
<tr>
<td>Support Staff</td>
<td><?php echo $row_DetailRS1['supportStaff']; ?></td>
</tr>
<tr>
<td>Active</td>
<td><?php echo $row_DetailRS1['active']; ?></td>
</tr>
<tr>
<td>Deceased</td>
<td><?php echo $row_DetailRS1['deceased']; ?></td>
</tr>
<tr>
<td>Comments</td>
<td><?php echo $row_DetailRS1['comments']; ?></td>
</tr>
</table>
</body>
</html><?php
mysql_free_result($DetailRS1); ?>
당신은 배열로 보면 하나 라이너로 그 horid ELSEIF 블록을 변경하여 시작할 수 있습니다. – quickshiftin