Note that there are some explanatory texts on larger screens.

plurals
  1. POPulling data from MySql into an array, then comparing the array's data to an existing variable
    primarykey
    data
    text
    <p>I have an application I am working on, this was produced in Dreamweaver CS5. The code is quite rediculous, the person that made the site is not able to help so I am struggling through the code and trying to "simplify" some of it as I can. I am more of a beginner-intermediate with php. So it seems as if it could be not so difficult. Description of what the application "should" do: The customer table should display the data(which it does) and should show Prefix, Suffix, and State from the tables, however it has auto increment id's for the primary key and the text portion will not display, only the numbers. So my predecessor used if else statements to convert the number to data (you will see in the code how cumbersome this is). So here is my code:</p> <pre><code>&lt;?php require_once('Connections/customer.php'); ?&gt;&lt;?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION &lt; 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."&lt;br/&gt;&lt;br/&gt;".mysql_error()); ?&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;link href="css/style.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;table width="41%" border="0" align="center" cellpadding="2" cellspacing="5"&gt; &lt;tr&gt; &lt;td width="157"&gt;Id&lt;/td&gt; &lt;td width="469"&gt;&lt;?php echo $row_DetailRS1['id']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Prefix&lt;/td&gt; &lt;td&gt;&lt;?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. &amp;amp; Mrs.'; } else if($row_DetailRS1['prefix']==5) { echo 'Dr.'; } else if($row_DetailRS1['prefix']==6) { echo 'Dr. &amp;amp; Mrs.'; } else if($row_DetailRS1['prefix']==7) { echo 'Mr. &amp;amp; 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. &amp;amp; Mrs.'; } else if($row_DetailRS1['prefix']==11) { echo 'Mr. &amp;amp; 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. &amp;amp; Mrs.'; } else if($row_DetailRS1['prefix']==15) { echo 'Atty.'; } else if($row_DetailRS1['prefix']==16) { echo 'Atty. &amp;amp; Mrs.'; } else if($row_DetailRS1['prefix']==17) { echo 'Mr. &amp;amp; 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 &amp;amp; Mrs.'; } else if($row_DetailRS1['prefix']==21) { echo 'Mrs. &amp;amp; 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. &amp;amp; Mrs.'; } else if($row_DetailRS1['prefix']==25) { echo 'Mr. &amp;amp; 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'; }; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Business Name&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['businessName']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;First Name&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['firstName']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Spouse Name&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['spouseName']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Last Name&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['lastName']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Suffix&lt;/td&gt; &lt;td&gt;&lt;?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.'; }; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Address&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['address']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Address Continued&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['addressCont']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;City&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['city']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;State&lt;/td&gt; &lt;td&gt;&lt;?php while($row = mysql_fetch_assoc($customer, $result)) { if($row_DetailRS1['state'] == $row) { echo '$row';}} ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Zip Code&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['zipCode']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Phone Number&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['phoneNum']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Alt. Phone Number&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['altPhoneNum']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;E-mail&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['email']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Board Member&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['boardMember']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Trustee&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['trustee']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Musician&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['musician']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Support Staff&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['supportStaff']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Active&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['active']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Deceased&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['deceased']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Comments&lt;/td&gt; &lt;td&gt;&lt;?php echo $row_DetailRS1['comments']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;&lt;?php mysql_free_result($DetailRS1); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload